skip legend entries while plotting data
13 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have following issue:
I'm plotting multiple graphs on the same figure. Before plotting them, there are some data interpolation. It can be that some of the data is empty set. the plotting command is like that:
plot(Ax, Ay, 'bo', Bx, By, 'go', Cx, Cy, r*)
legend('A', 'B', 'C')
When set A (Ax, Ay), for example, is empty (and there is data in B & C sets), in the generated label, it will associate set A to green color, B to red color and it will not display the C legend.
How to solve the issue that if there is empty set, it will skip it in the legend?
Thank you!
0 comentarios
Respuestas (3)
Rik
el 10 de Oct. de 2017
Editada: Rik
el 10 de Oct. de 2017
I use multiple calls to plot, so I can get a list of handles, which you can then use in the call to legend
h=[];
h(1)=plot(rand(2));hold on
h(2)=plot(0:0.1:1);
legend(h,{'A','B'})
edit: don't forget hold on (which I tend to do often, apparently even in answering here)
0 comentarios
sandeep singh chauhan
el 1 de Ag. de 2018
Suppose I have a vector A1 and B1 denotes its corresponding legends and I want to skip the legends for zeros in A1 means I don't want legend 'D','G','H','I'
A1 = [ 1 2 3 0 4 5 0 0 0 8]; B1 = {'A','B','C','D','E','F','G','H','I','J'}; D1 = []; for i =1:length(A1) if (A1(i) ~=0) C1 = i; plot(A1(i):A1(i)+20); %% example for plot D1 = [D1;strcat(B1(C1))]; legend(D1); hold on end
end
0 comentarios
sandeep singh chauhan
el 12 de Ag. de 2018
A1 = [ 1 2 3 0 4 5 0 0 0 8]; B1 = {'A','B','C','D','E','F','G','H','I','J'}; D1 = []; for i =1:length(A1) if (A1(i) ~=0) C1 = i; plot(A1(i):A1(i)+20); %% example for plot D1 = [D1;strcat(B1(C1))]; legend(D1); hold on end
end
0 comentarios
Ver también
Categorías
Más información sobre Legend en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!