How to change the color of the line in the legend of the figure?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Lucy
el 28 de Nov. de 2024
Respondida: Star Strider
el 28 de Nov. de 2024
How to change the color of the line in the legend of the figure? I have changed the color of the curves in my figure for several times but the line color did not change correspondingly with them.
0 comentarios
Respuesta aceptada
Star Strider
el 28 de Nov. de 2024
It would help to have your code and data.
The legend entries correspond to the lines being plotted, and if there are more than one line, this can cause ptoblems.
You may need to speciifically reference each separate plot call.
Example —
x = linspace(0, 1, 1E+3).';
y = sin(2*pi*x*(1:5:25)) + (1:5)
figure
plot(x, y(:,1:3), 'b')
hold on
plot(x, y(:,4:5), 'r')
hold off
grid
legend('y_1','y_2') % No Specific References
figure
hp1 = plot(x, y(:,1:3), 'b');
hold on
hp2 = plot(x, y(:,4:5), 'r');
hold off
grid
legend([hp1(1) hp2(1)], 'y_1','y_2') % With Specific References
.
0 comentarios
Más respuestas (0)
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!