Legend plot wrong colors

조회 수: 7 (최근 30일)
Matthias Wernerus
Matthias Wernerus 2019년 10월 2일
답변: Bhargavi Maganuru 2019년 10월 11일
Hi i would like to plot several datasets in one fig. also i have to xline functions in the fig. i would like to add a legen but only for the plots. how can i do that? i keep getting the wrong colors to the datasets.
figure(1);
plot(y_l,BSS03); hold on
plot(y_l,BSS04); hold on
plot(y_l,BSS05);
hold on
xl1= xline(576,'r','576 m');
xl1.LabelVerticalAlignment = 'bottom';
xl2= xline(680,'r','680 m');
xl2.LabelVerticalAlignment = 'bottom';
yline(0);
legend({'0,3','0,4', '0,5'})
xlabel('y [m]')
ylabel('BSS')
title('BSS entlang der Küste');

답변 (1개)

Bhargavi Maganuru
Bhargavi Maganuru 2019년 10월 11일
To skip the legend for a plot you can set ‘HandleVisibility’ property to ‘off’
For the plot in your code
plot(y_l,BSS03,'HandleVisibility','off');
If you add or delete a data series from the axes, the legend updates accordingly.
Also, you can specify the legend labels during the plotting commands by setting the ‘DisplayName’ property to the desired text. Then, add a legend.
For the plot in your code
plot(y_l,BSS03,'DisplayName','0.3');
legend;
For more information about legend you can refer to the link https://www.mathworks.com/help/matlab/ref/legend.html
Hope this helps!

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!