How do I change the size of subplots in stackedplot
6 views (last 30 days)
Show older comments
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 Comments
jessupj
on 9 Jun 2020
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...
Answers (2)
Ayush Gupta
on 12 Jun 2020
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 Comments
jessupj
on 12 Jun 2020
this isn't a question about plotting multiple data on a common axis; it is a question about sizing of subplots
Adam Danz
on 19 Nov 2020
Edited: Adam Danz
on 12 May 2021
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 Comments
See Also
Categories
Find more on Line Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!