Legend for scatter plot has lines through markers

12 visualizaciones (últimos 30 días)
Amy Robertson
Amy Robertson el 12 de Sept. de 2018
Editada: jonas el 12 de Sept. de 2018
Hi, I am creating a scatter plot that uses different markers, which I access from a vector. When I add a legend to the plot, these markers show up correctly, but there is a line through them, which I would like to remove.
Here is a simple example. If you create the following plot, you will get what you would expect. A legend with just the marker symbol next to the label 'Case 1'. plot(1,1,'*'); legend('Case 1');
However, if you create a plot in the following manner (see below), the legend will now have a line through that marker. I'm wondering if there is a way to remove or turn-off that line? I need to do this latter approach since I am plotting multiple points in a scatter plot, and accessing different markers using a vector of symbols.
plot(1,1,'marker','*'); legend('Case 1');
Thanks!
  1 comentario
Amy Robertson
Amy Robertson el 12 de Sept. de 2018
Okay, very shortly after I posted this question, I figured it out. One needs to simply remove the 'marker' option from the command. So, even if you want to access a vector of symbols, you can just state that directly. For instance:
plot(1,1,mark_sym(i)); legend('Case 1');
In this case it will find the symbol in the vector mark_sym and use the appropriate symbol. One does not have to say:
plot(1,1,'marker',mark_sym(i)); legend('Case 1');
which will create an extra line through that marker in the legend.

Iniciar sesión para comentar.

Respuesta aceptada

jonas
jonas el 12 de Sept. de 2018
Editada: jonas el 12 de Sept. de 2018
The third argument in plot sets the line style and markerstyle. If you do not specify a 3rd argument then plot assigns a line per default. If you use your second option, then you add a marker to the already existing line and you have to change the linestyle after plotting.
h=plot([1],[1],'marker','*');
legend('Case 1');
set(h,'linestyle','none')

Más respuestas (0)

Categorías

Más información sobre Legend en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by