Legend plot wrong colors

3 次查看(过去 30 天)
Matthias Wernerus
Matthias Wernerus 2019-10-2
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!