Multiple linkaxes calls on subplots?

8 vues (au cours des 30 derniers jours)
joey101
joey101 le 10 Juil 2017
Commenté : Ziad Sliti le 25 Fév 2022
Hi, I'm trying to link the plots in two figures and their subplots in a specific way.
I'm making two 1xN figures and want:
  • All of the x axes to be linked.
  • The y axis of the first subplot in figure 1 linked to the first subplot's y axis in figure 2.
  • The y axis of the rest of the subplots(2-N) in both figures all linked.
figure
sp3=zeros(1,N);
for k = 1:N
sp3(k) = subplot(N,1,k);
plot(x,y(:,k));
title(strcat(Titles{k},{' Original'}));
xlabel('Time (s)');
ylabel('Voltage');
end
set(findall(gcf,'-property','FontSize'),'FontSize',12) ;
figure
sp4=zeros(1,N);
for k = 1:N
sp4(k) = subplot(N,1,k);
plot(x,y_edited(:,k));
title(strcat(Titles{k},{' Edited'}));
xlabel('Time (s)');
ylabel('Voltage');
end
set(findall(gcf,'-property','FontSize'),'FontSize',12) ;
linkaxes([sp3(1),sp4(1)],'y');
linkaxes([sp3(2:end),sp4(2:end)],'y');
linkaxes([sp3,sp4],'x');
Unfortunately, this isn't working, the y axes are not linking, this is particularly evident when zooming.
Any suggestions would be great! Thanks!
  6 commentaires
joey101
joey101 le 11 Juil 2017
Nah linkaxes has always extended all of the limits to the largest of the axes linked.
Adam
Adam le 11 Juil 2017
You must just be lucky because the help for linkaxes says:
'The first axes you supply to linkaxes determines the x- and y-limits for all linked axes'

Connectez-vous pour commenter.

Réponses (2)

Elliot Claveau
Elliot Claveau le 21 Juin 2018
I found that using "linkprop" saves the properties over multiple call (as long as you define the variable "link1, link2..."). For example, I linked the Y axis of the top row, and the Y axis of the bottom row independently. With the third call, I was able to link all the X axis together, keeping the independent link between the Y axis.
ax{1,1} = subplot(2,2,1);
ax{1,2} = subplot(2,2,2);
ax{2,1} = subplot(2,2,3);
ax{2,2} = subplot(2,2,4);
link1 = linkprop([ax{1,1},ax{1,2}], 'YLim');
link2 = linkprop([ax{2,1},ax{2,2}], 'YLim');
link3 = linkprop([ax{1,1},ax{1,2},ax{2,1},ax{2,2}],'XLim');
  1 commentaire
Ziad Sliti
Ziad Sliti le 25 Fév 2022
That works for me !
Thank you for the tips, you have to define variable to keep multiple call of linkprop active.

Connectez-vous pour commenter.


Steven Lord
Steven Lord le 10 Juil 2017
"Note: linkaxes is not designed to be transitive across multiple invocations. If you have three axes, ax1, ax2, and ax3 and want to link them together, call linkaxes with [ax1, ax2, ax3] as the first argument. Linking ax1 to ax2, then ax2 to ax3, "unbinds" the ax1-ax2 linkage."
  3 commentaires
Jan
Jan le 11 Juil 2017
How do you zoom in the axes? You can incluide Callbacks in the zoom() function, which can set the limits of the other axes accordingly. This is less convenient than linked properties, but there are no limitations in what you include in the callback function.
joey101
joey101 le 11 Juil 2017
visually with my mouse

Connectez-vous pour commenter.

Catégories

En savoir plus sur Graphics Object Properties dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by