Line marker specifiers duplicated - subplot legend

21 visualizaciones (últimos 30 días)
Vineet
Vineet el 5 de Feb. de 2015
Comentada: Mike Garrity el 6 de Feb. de 2015
I am using subplots (3X4) in a figure. I have 9 plots which means in the third row, plots 10, 11, and 12 are free. I am trying to put my legend in the space of plot 10. Could anyone explain why there are some extra symbols creeping in between (shown inside the red circle in picture)? The relevant part of my code is as follows:
subplot(3,4,10)
axis off
plot(p1, 'ks', 'MarkerEdgeColor','k', 'MarkerFaceColor','w','MarkerSize',8);
axis off
plot(p2, 'ko', 'MarkerEdgeColor','k', 'MarkerFaceColor','k','MarkerSize',5);
hold on;
axis off
plot(p3, 'k^', 'MarkerEdgeColor','k', 'MarkerFaceColor','w','MarkerSize',7);
hold on;
axis off
plot(p4, 'k^', 'MarkerEdgeColor','k', 'MarkerFaceColor','k','MarkerSize',7);
hold on;
axis off
plot(p5, '-k', 'MarkerEdgeColor','k', 'MarkerFaceColor','k','MarkerSize',2);
hold on;
axis off
plot(p6, '--k', 'MarkerEdgeColor','k', 'MarkerFaceColor','k','MarkerSize',2);
hold on;
legend(...
'abc',...
'abc',...
'abc',...
'abc',...
'abc',...
'abc',...
'Location', 'North');
legend('boxoff')
title('Legend')

Respuesta aceptada

Mike Garrity
Mike Garrity el 5 de Feb. de 2015
Are you sure you're not just seeing your plots behind the legend? Things are pretty crowded in that tiny axes. What happens if you add this:
set(get(gca,'Children'),'Visible','off')
to hide the plots in that axes.
BTW, I don't think your code actually matches the picture. Your code doesn't do "hold on" until after you plot p2. That means that plotting p2 would have overwritten p1. And yet we can see some square markers.
  2 comentarios
Vineet
Vineet el 5 de Feb. de 2015
Hi Mike, That is great, it solved the problem. I would like to know what is happening here. What does 'Children' stand for? BTW, you were right, when I copied my and pasted, a 'hold on' after 'p1' went missing. Thank you!
Mike Garrity
Mike Garrity el 6 de Feb. de 2015
Children is a property on the axes which holds references to all of the objects that those plot command put there. They're the same objects that plot is returning if you had said
h = plot(...)
So that code snippet says "take the results of all of the plots commands and make them invisible". That way I have an axes which contains the right set of lines to make the legend, but I can't see them.
Note that this isn't the same as
axis off
That just hides all of the axes decorations such as tick labels. It doesn't hide the children.

Iniciar sesión para comentar.

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