How to change the color of the line in the legend of the figure?
19 views (last 30 days)
Show older comments
Lucy
on 28 Nov 2024 at 16:04
Answered: Star Strider
on 28 Nov 2024 at 16:22
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 Comments
Accepted Answer
Star Strider
on 28 Nov 2024 at 16:22
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 Comments
More Answers (0)
See Also
Categories
Find more on Legend in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!