Is there a way to link the left and right y-axes on a GUI Axes after using yyaxis?

38 次查看(过去 30 天)
I haven't been able to find any documentation on it and linkaxes() specifies 'axes' in particular rather than a particular axis attached to an axes. I have plotted the data that I have on each y-axis, but when I use 'zoom', it only zooms on one of the two y-axes. Example code below is from the Matlab documentation for yyaxis:
x = linspace(0,10);
y = sin(3*x);
yyaxis left
plot(x,y)
z = sin(3*x).*exp(0.5*x);
yyaxis right
plot(x,z)
ylim([-150 150])
% linkaxes((yyaxis left)? (yyaxis right)?)
I'm not able to save each yy-axis to a variable so I can't reference it that way either. Any help with this is greatly appreciated!
  4 个评论
Adam
Adam 2018-7-13
You'd probably be better off explicitly using two axes in the same location and putting the axis of one on the right. The whole yyaxis thing seems very underwhelming to me whenever I've used it in terms of functionality it allows. I don't really know why it was programmed the way it was, but it isn't user friendly, not consistent with being able to work with explicit axes handles for plotting-related instructions.

请先登录,再进行评论。

回答(1 个)

Luis
Luis 2019-3-18
编辑:Luis 2019-3-18
There is a function similar to 'linkaxes' call 'linkprop' that do the trick. You only need to link the 'Limits' property on each YAxis. Here an example code:
% Create some plot
x=0:100;
plot(x,sin(.1*x).^2*1000);
grid on
% Add a second axis
yyaxis right
ax=gca();
ax.YAxis(2).TickValues = [10 100 1000];
ax.YTickLabel = {'10^1','10^2','10^3'};
%% Link the 'Limits' property
r1=ax.YAxis(1);
r2=ax.YAxis(2);
linkprop([r1 r2],'Limits')

类别

Help CenterFile Exchange 中查找有关 Visual Exploration 的更多信息

产品


版本

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by