How do I change the size of subplots in stackedplot

조회 수: 11 (최근 30일)
David Duncan
David Duncan 2020년 6월 9일
편집: Adam Danz 2021년 5월 12일
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
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...
David Duncan
David Duncan 2020년 6월 15일
That does indeed look like a good solution to my problem, thank you. Shame there doesn't appear to be any flexibility with the Mathwork's stackedplot though.

댓글을 달려면 로그인하십시오.

답변 (2개)

Ayush Gupta
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
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
David Duncan
David Duncan 2020년 6월 15일
편집: David Duncan 2020년 6월 15일
I would argue it is about plotting multiple data on the same X-axis, but different Y-axis and being able to control the respective sizes of the y-axes, but it can indeed be achieved by resizing subplots and simply making sure that the limits of each x-axis are the same.
(But indeed it is not a "hold" issue).

댓글을 달려면 로그인하십시오.


Adam Danz
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;

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by