two extremely odd behavior using plotyy

1 次查看(过去 30 天)
Leo Simon
Leo Simon 2020-10-24
评论: Leo Simon ,2020-10-24
My matlab version is 2020a. The following code has two problems. Are they really indended behavior??
1) there are eight lines, but the legend command insists that there are only seven
2) the first entries in YY{1,2} and YY{2,2} are identical, yet when plotted, the are different.
Can somebody please suggest a way to fix this, i.e., have the legend recognize all eight lines, and have the first elements of YY{1,2} and YY{2,2} be coincident?
Thanks very much for any suggestions
YY{1,1} = [ -0.1479019945775 -0.1207614728849 -0.0853912563830
-0.1332722959302 -0.1088113389903 -0.0769390531180
-0.1204885338805 -0.0983676376342 -0.0695513925373];
YY{2,1} = [ -0.1479019945775 -0.1207614728849 -0.0853912563830
-0.1315463790731 -0.1074015009182 -0.0759418727129
-0.1170135908441 -0.0955291160389 -0.0675440123853];
YY{1,2} = [ 1.8095706646177
YY{2,2} = [ 1.8095706646177
close all;
hold on;

回答(1 个)

Walter Roberson
Walter Roberson 2020-10-24
hold on is holding the default ylim but some of your data is below that.
hold on does not affect all axes, only the current axes.
plotyy will reuse the current axes if hold is on for it, but it will always generate a new second axes. You therefore have three active axes. First plotyy uses the active axes because hold is already on, and generates ax2. Second plotyy reuses the current axes ax1 and generates ax3.
automatic range generation on the two unheld axes is not going to be the same as each other.
  1 个评论
Leo Simon
Leo Simon 2020-10-24
Thanks very much Walter, I put back in the handles from my original code, presumably the 3rd axis is represented by one of the handles, but I don't understand how they really work. Could you explain how I would get all 8 lines in the legend, please?



Help CenterFile Exchange 中查找有关 Two y-axis 的更多信息


Community Treasure Hunt

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

Start Hunting!

Translated by