Multiple linkaxes calls on subplots?

7 views (last 30 days)
joey101
joey101 on 10 Jul 2017
Commented: Ziad Sliti on 25 Feb 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 Comments
joey101
joey101 on 11 Jul 2017
Nah linkaxes has always extended all of the limits to the largest of the axes linked.
Adam
Adam on 11 Jul 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'

Sign in to comment.

Answers (2)

Elliot Claveau
Elliot Claveau on 21 Jun 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 Comment
Ziad Sliti
Ziad Sliti on 25 Feb 2022
That works for me !
Thank you for the tips, you have to define variable to keep multiple call of linkprop active.

Sign in to comment.


Steven Lord
Steven Lord on 10 Jul 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 Comments
Jan
Jan on 11 Jul 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 on 11 Jul 2017
visually with my mouse

Sign in to comment.

Categories

Find more on Graphics Object Properties 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!