Legend plot wrong colors

7 vues (au cours des 30 derniers jours)
Matthias Wernerus
Matthias Wernerus le 2 Oct 2019
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');

Réponses (1)

Bhargavi Maganuru
Bhargavi Maganuru le 11 Oct 2019
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!

Tags

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!