Dynamic Legends plot option (error: two legend lines for each plot)
조회 수: 2 (최근 30일)
이전 댓글 표시
I have a function which makes a plot from different vectors, then each time that I add a new plot I need to add a new legend which is a variable(legend) now I trying to do it with the next code:
plot_test = plot(vector1, vector2, '-mo','Color',color, 'DisplayName',legend);
hold all;
legend('-DynamicLegend');
but as result I got two new legends for each plot, one whith the real name and another called line2, line4, line6....and so on depending the number of plots...
Any help please?
댓글 수: 0
채택된 답변
Azzi Abdelmalek
2013년 9월 3일
편집: Azzi Abdelmalek
2013년 9월 3일
Look at this example
x=0:0.1:10;
y1=sin(x);
plot(x,y1)
hl=legend('leg1')
hold all
y2=cos(x)
plot(x,y2)
leg=[get(hl,'string'), 'leg2']
hl=legend(leg)
댓글 수: 3
Azzi Abdelmalek
2013년 9월 3일
Add to your input and output argument of your function the handles old_hl and hl
추가 답변 (1개)
Robert Cumming
2013년 9월 3일
Is this the type of feature your after:
figure;
x = [0:0.01:2*pi];
hold on;
plot ( x, sin (x), 'DisplayName', 'Plot A' )
legend ( '-dynamicLegend' )
plot ( x,- sin (x), 'r', 'DisplayName', 'Plot B' )
plot ( x, 2*sin (x), 'g', 'DisplayName', 'Plot C' )
참고 항목
카테고리
Help Center 및 File Exchange에서 Legend에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!