Missing legend entries on plotyy

7 ビュー (過去 30 日間)
David
David 2012 年 11 月 7 日
Hi,
I am attempting to plot data on to a graph with two different y axis. I used the plotyy function. To plot four functions on the same plot I use the hold on command. When I attempt to add a legend to the graph it only has three entries. Example code below:
x=0:0.1:10;
y1=x.^2;
y2=log(x);
y3=2*x.^2;
y4=2*log(x);
[AX,L1,L2]=plotyy(x,y1,x,y2)
set(L1,'Color','b');
set(L2,'Color','g');
hold on
[AX,L3,L4]=plotyy(x,y3,x,y4)
set(L3,'Color','b','marker','x');
set(L4,'Color','g','marker','x');
legend('y1','y2','y3','y4')
hold off
'y4' is left off of the legend box when I run the above code. Any suggested modifications to the above code that would allow the legend box to show all four entries would be much appreciated. Thanks, David

採用された回答

Sean de Wolski
Sean de Wolski 2012 年 11 月 7 日
Explicitly tell legend() which lines to draw:
legend([L1 L2 L3 L4],'y1','y2','y3','y4')
  1 件のコメント
David
David 2012 年 11 月 7 日
Perfect.
Thanks very much Sean.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTwo y-axis についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by