plotyy and legend display

hi everyone, i'm trying to plot multiple graphs on a plot using multiple y-axes
i'm using the plotyy function and everything is going smoothly except for when i want to call the legend.
right now, I have to call legend twice (once for the series on the primary y axis, and once for the series plotted on the secondary y-axis) so there are 2 legend boxes on the plot.
is there a way to show just one legend box with all the series displayed in it from both the primary and secondary axes?

답변 (1개)

Thomas
Thomas 2012년 5월 9일

0 개 추천

If you are calling the legend like this now..
[AX,H1,H2] = plotyy(x,y1,x,y2,'plot','plot');
legend(H1,'y1');
legend(H2,'y2');
you could try
legend([H1;H2],'y1','y2');

댓글 수: 1

David C
David C 2012년 5월 9일
i don't think it work, but maybe i did it wrong, so to elaborate, i have 3 functions on the primary y-axis, and 2 functions on the secondary y-axis
i called the legend initially just like how you described it, but after your suggestion, i tried the following:
legend([haxes(1),haxes(2)],{'fxn1' 'fxn2' 'fxn3'},{'fxn4' 'fxn5'});
running this line put a legend with only fxn4, and fxn5 in the legend box
please advise

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Two y-axis에 대해 자세히 알아보기

질문:

2012년 5월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by