Ultimately, I handled this issue by giving up on the yy plot and did a subplot instead. I, nor a couple colleagues, was not able to get the legend to display all entries for the yyplot.
legend entries ignored after using "hold" to create plots
3 次查看(过去 30 天)
显示 更早的评论
I created a yy plot using "hold on" because my data sets were different lengths. Since then, the legend function only recognizes 4 of the 6 data sets plotted so when I add the legend it is incomplete. Can anyone tell me how to get the other entries to show up or maybe there is a better way to plot data sets with different lengths than using the "hold" function.
Thanks!
0 个评论
采纳的回答
更多回答(1 个)
Thomas
2014-1-28
You could concatenate multiple legend statements for the two data sets
Eg.:
x = 1900:10:1990; x=x'
y1 = 10:10:100; y1=y1'
y2 = -0.1:-0.1:-1; y2=y2'
y3 = 0.05:0.05:0.5; y3=y3'
[AX,H1,H2] = plotyy(x,y1,x,[y2,y3],'plot','plot');
legend(H1,'y1');
legend(H2,'y2','y3');
this will give you only the last legend on the plot
x = 1900:10:1990; x=x'
y1 = 10:10:100; y1=y1'
y2 = -0.1:-0.1:-1; y2=y2'
y3 = 0.05:0.05:0.5; y3=y3'
[AX,H1,H2] = plotyy(x,y1,x,[y2,y3],'plot','plot');
legend([H1;H2],'y1','y2','y3');
this will give the entire data set with legend
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Legend 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!