How do I change the size of subplots in stackedplot
9 次查看(过去 30 天)
显示 更早的评论
I am trying to plot a series of related data together (sharing the same x-axis). Most sets of the data cover a very similar y range (0-1), but one of the data sets cover a comparably larger range (0-2). I desire each plot to be on its own y-axis, but with a shared x-axis, but I'd like the size of each subplot to match the total y-range that the respective data covers. So my script looks something like:
data1_raw = rand(11,1);
data1_fit = repmat(mean(data1_raw),11,1);
data2_raw = 2*rand(11,1);
data2_fit = repmat(mean(data2_raw),11,1);
t = table(data1_raw,data1_fit,data2_raw,data2_fit);
s = stackedplot(t,{{'data1_raw','data1_fit'},{'data2_raw','data2_fit'}});s.AxesProperties.plot_start = [0 0.33] %set the start position of each sub plot
What I get from this is the below plot:
What I want is this plot:
2 个评论
jessupj
2020-6-9
basically, you'd do this via:
subplotX = @(m,n,p) subtightplot (m, n, p, [0.01 0.05], [0.1 0.01], [0.1 0.01]);
subplotX(3,1,1)
% plot first fig...
subplotX(3,1,[2 3])
% plot second fig...
回答(2 个)
Ayush Gupta
2020-6-12
MATLAB has hold on feature which allows to plot multiple graphs on the same figure. Refer to the following link to know more about hold on:
A Use case example:
plot(t.data1_raw);
hold on
plot(t.data1_fit);
plot(t.data2_raw);
plot(t.data2_fit);
hold off
2 个评论
jessupj
2020-6-12
this isn't a question about plotting multiple data on a common axis; it is a question about sizing of subplots
Adam Danz
2020-11-19
编辑:Adam Danz
2021-5-12
You can get the axis handles of stackedplot using the undocumented NodeChildren property. Use flipud to set the axis handles in order of the axes as they appear in the plot. Then resize the axes as usual.
However, resizing the figure triggers a listener that resets the axes to their original positions. I haven't looked for the listener but perhaps a workaround would be to set the figure's SizeChangedFcn to restore the custom axes positions. Or, consider using stackedaxes from the file exchange.
s = stackedplot(1:50, rand(50,2));
ax = flipud(findobj(s.NodeChildren, 'Type','Axes'));
ax(1).Position([2,4]) = [.7, .12];
ax(2).Position(4) = .57;
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!