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

31 ビュー (過去 30 日間)
Thomas Schill
Thomas Schill 2018 年 7 月 11 日
編集済み: Luis 2019 年 3 月 18 日
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.
Thomas Schill
Thomas Schill 2018 年 7 月 13 日
I think I can make that work! Thank you!

サインインしてコメントする。

回答 (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 Center および File ExchangeData Exploration についてさらに検索

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by