two extremely odd behavior using plotyy
2 次查看(过去 30 天)
显示 更早的评论
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
1.6688286822702
1.5392601779117];
YY{2,2} = [ 1.8095706646177
1.6517555878194
1.5033917356162];
close all;
hold on;
[hPlotyy{1},plotyyAx{1,1},plotyyAx{2,1}]=plotyy([1:3],YY{1,1},[1:3],YY{1,2})
[hPlotyy{2},plotyyAx{1,2},plotyyAx{2,2}]=plotyy([1:3],YY{2,1},[1:3],YY{2,2});
legend
0 个评论
回答(1 个)
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Two y-axis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!