linkaxes of different stackedplots

조회 수: 42 (최근 30일)
EK
EK 2020년 10월 30일
편집: Adam Danz 2020년 11월 24일
Hi,
To display different signals with the same x-axis I used stackedplot. To compare different events of the signals I used subplot to display different stackplots side by side (in columns).
I would like to connect the axes, i.e. when I zoom or move a signal, this is done for all the signals of the other subplots as well.
If I want to use linkaxes, I get the error message: "There must be at least one valid axes."
Can anyone help me?
Here is the simplified code, which should run for everyone
X = [0:4:20];
Y = randi(100,6,3);
hAx(1) = subplot(1, 2, 1);
s = stackedplot(X,Y);
s.title('Plot 1');
hAx(2) = subplot(1, 2, 2);
s = stackedplot(X,Y);
s.title('Plot 2');
% linkaxes(hAx, 'x');
linkaxes([hAx(1) hAx(2)],'x')
  댓글 수: 2
Adam Danz
Adam Danz 2020년 10월 30일
편집: Adam Danz 2020년 11월 18일
If you look at hAx(1) or hAx(2) after creating the two stackedplots you'll notice that they are handles to deleted axes. That's because the stackedplots replace the subplots.
stackedplot handles are not axes so you cannot use them with linkaxes.
linkprop([s1,s2],'XLimits') also didn't work, where s1 and s2 are the two stackedplot handles.
The XLimits property is not defined to be SetObservable so adding a listener would also not work.
Bummer....
EK
EK 2020년 11월 2일
oh crap, thanks for the help. Do you know a similar plot like Stackedplot, which allows you to zoom the subplots at the same time (for example with linkaxes)?

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

답변 (1개)

Adam Danz
Adam Danz 2020년 11월 19일
편집: Adam Danz 2020년 11월 24일
I found a solution (weeks later) using the undocumented NodeChildren property to get the axis handles.
Instead of using the subplot command to position the stackedplot objects, you can specify their parent object as a panel, tab, tiledLayout, or gridLayout (see this answer).
fig = figure();
tlo = tiledlayout(fig,1,2);
nexttile(tlo);
s1 = stackedplot(rand(20,4),'Parent',tlo);
nexttile(tlo);
s2 = stackedplot(rand(20,4),'Parent',tlo);
% Get axes
ax1 = findobj(s1.NodeChildren, 'Type','Axes');
ax2 = findobj(s2.NodeChildren, 'Type','Axes');
linkaxes([ax1,ax2],'x')
  댓글 수: 1
Seth Furman
Seth Furman 2020년 11월 20일
@EK, would it meet your use case to combine horizontally adjacent sub-plots from these side-by-side stacked plots?
For example
rng default
X = 0:4:20;
Y = randi(100,6,6);
stackedplot(array2table([X' Y]),{[1 4] [2 5] [3 6]},'XVariable',1);

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

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by