- call legend with a single legend entry, such as inside a loop or trying to place the legend call for each plot() right after the associated plot(); or call legend passing in only one graphics object handle
is there any way to put two plots in one legend entry?
44 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Fuad Nammas
el 17 de Sept. de 2019
Comentada: Fuad Nammas
el 21 de Sept. de 2019
is it possible to combine multiple plots in one legend entry as shown in the picture? . I tried various operations with [] and () but it didn't work.
Is there a way to put two plots in one legend entry?
0 comentarios
Respuesta aceptada
Walter Roberson
el 18 de Sept. de 2019
That happens automatically unless you do one of the following:
Some of the approaches that work are:
A)
for K = 1 : 6
this_x = something(K,:);
this_y = someother(K,:);
thislegend = sprintf('R%d', K); %construct a legend string
legends{K} = thislegend; %record it
plot(this_x, this_y);
hold on
end
legend(legends);
B)
for K = 1 : 6
this_x = something(K,:);
this_y = someother(K,:);
thislegend = sprintf('R%d', K); %construct a legend string
legends{K} = thislegend; %record it
linehandles(K) = plot(this_x, this_y);
hold on
end
legend(linehandles, legends);
C)
for K = 1 : 6
this_x = something(K,:);
this_y = someother(K,:);
thislegend = sprintf('R%d', K); %construct a legend string
linehandles(K) = plot(this_x, this_y, 'DisplayName', thislegend);
hold on
end
legend(linehandles, 'show');
D)
for K = 1 : 6
this_x = something(K,:);
this_y = someother(K,:);
plot(this_x, this_y);
hold on
end
legend({'R1', 'R2', 'R3', 'R4', 'R5', 'R6'});
0 comentarios
Más respuestas (1)
Fuad Nammas
el 18 de Sept. de 2019
Editada: Fuad Nammas
el 18 de Sept. de 2019
2 comentarios
Walter Roberson
el 19 de Sept. de 2019
h = plot(T,I1/nm,'r',T,I11/nm,'--r',T,I2/nm,'b',T,I22/nm,'--b',T,I3/nm,'k',T,I33/nm,'--k');
legend(h(1:2:end), {'R_1=a_B','R_2=1.2a_B','R_3=1.4a_B'})
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!