linkaxes of different stackedplots
38 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Adam Danz
le 30 Oct 2020
Modifié(e) : Adam Danz
le 18 Nov 2020
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....
Réponses (1)
Adam Danz
le 19 Nov 2020
Modifié(e) : Adam Danz
le 24 Nov 2020
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 commentaire
Seth Furman
le 20 Nov 2020
@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);
Voir également
Catégories
En savoir plus sur Surface and Mesh Plots dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!