MATLAB Answers

Legend plot wrong colors

11 views (last 30 days)
Matthias Wernerus
Matthias Wernerus on 2 Oct 2019
Answered: Bhargavi Maganuru on 11 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');

  0 Comments

Sign in to comment.

Answers (1)

Bhargavi Maganuru
Bhargavi Maganuru on 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!

  0 Comments

Sign in to comment.

Tags

Products


Release

R2019b