0

I want to plot both lines of my estimations and dots of data.

And add legend only for lines.

Here is my matlab code.

%plot lines
%-----------------------------------------
p_me = plot(real(G_me),imag(G_me));
p_me.Color = '#A2142F' %red
hold on;

p_0 = plot(real(G_0),imag(G_0));
p_0.Color = '#EDB120' %yellow

p_1 = plot(real(G_1),imag(G_1));
p_1.Color = '#77AC30' %green

p_2 = plot(real(G_2),imag(G_2));
p_2.Color = '#4DBEEE' %light blue

p_3 = plot(real(G_3),imag(G_3));
p_3.Color = '#0072BD' %blue

p_10 = plot(real(G_10),imag(G_10));
p_10.Color = '#7E2F8E' %purple

legend('1','2','3','4','5','6')

%plot dots
%-----------------------------------------
for i = (1:60)       
    for j = (1:100)
        if analyzedData(i).Md(j) < 10  plot(analyzedData(i).data(j,1),analyzedData(i).data(j,2),'k.','MarkerSize',3);
        end
    end
end

hold off;

It works, but it also add needless legends of every single dot. Like this enter image description here

How can I keep only legends of lines? What should I modify in my code?

GrossMatt
  • 41
  • 3
  • 1
    You can specify subsets of graphics objects to be included in your legend, cf. [this example](https://www.mathworks.com/help/matlab/ref/legend.html#bu_sz6u-1) from the MATLAB documentation on `legend`. – HansHirse Jan 28 '20 at 07:21
  • 1
    Also: Does this answer your question? [How to show legend for only a specific subset of curves in the plotting?](https://stackoverflow.com/questions/13685967/how-to-show-legend-for-only-a-specific-subset-of-curves-in-the-plotting) – HansHirse Jan 28 '20 at 07:23
  • The easiest way is to set the `HandleVisibility` property to `'off'` for your dots, as specified in one of the answers of the duplicate, i.e. `plot( ___, 'HandleVisibility', 'off' )`. – Wolfie Jan 28 '20 at 08:33

0 Answers0