skip legend entries while plotting data
14 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (3)
Rik
il 10 Ott 2017
Modificato: Rik
il 10 Ott 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 Commenti
sandeep singh chauhan
il 1 Ago 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 Commenti
sandeep singh chauhan
il 12 Ago 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 Commenti
Vedere anche
Categorie
Scopri di più su Legend in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!