How Can I Zoom with Multiple Axes on a Plot
23 次查看(过去 30 天)
显示 更早的评论
I create a plot and add a secondary x-axis. The code for the secondary x-axis came from dbp in a post that for the life of me I can't find.
xm = 0:10;
xcm = xm*100;
plot(xm,5*xm,'-x');
xlabel('meters');
h1 = get(gcf,'Children');
pos1 = h1.Position;
pos2 = pos1;
pos1(2) = pos1(2) + pos2(1);
pos1(4) = pos1(4) - pos2(1);
h1.Position = pos1;
h2 = axes('Position',pos2,'color','none');
h2.XColor = 'r';
h2.YColor = 'none';
set(gcf,'CurrentAxes',h1);
This gives me the plot I want. But when I zoom, the plot zooms only the second axes (the red one) and doesn't change the plot.
So the first question is: what controls which axes is affected by the zoom? I thought it would be the current axes, but apparently that's not the case.
More importantly, what needs to be done so that zooming on the plot does what's expected for the plot and both sets of axes, as is is the case when zooming after using plotyy? I looked at plotyy and saw some code about axes pointing to each other and using some ListenerManager. Is that what keeps the axes synched when zooming?
0 个评论
回答(1 个)
Nitin Kapgate
2020-10-5
You can use “linkaxes” function to synchronize the limits of the specified vector of axes. Synchronizing the axes limits for the specified axis dimension allows you to display the same range data between multiple axes in a figure.
For example, the following code synchronizes the limits for the x-axis only.
linkaxes([ax1, ax2, ax3],'x')
To open a demo example for using “linkaxes” function, you can enter the following in MATLAB command window:
openExample('graphics/LinkaxesSynchronizeLimitsExample')
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Axis Labels 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!