Hermi
Hermi

Reputation: 357

How to change the color of a line plot in the plane?

If I plot a line in the plane as following code

   plot(x, y,'k-', 'linew', 1.5)

How to change its color?

I try

   plot(x, y,'-r','k-', 'linew', 1.5)

but this does not work...

Upvotes: 0

Views: 1027

Answers (1)

MichaelTr7
MichaelTr7

Reputation: 4757

Taking out the -k (black line) will allow the new plot not to suppress the -r (red line). In this case MATLAB is trying to take the last colour specification given. For more plotting colours and settings: MATLAB Documentation: LineSpec - Line style, marker, and color.

%Arbitrary line data%
x = (0: 1: 100);
y = (0: 1: 100);

plot(x, y,'k-', 'linew', 1.5); %Black line plot indicated by -k%
plot(x, y,'-r', 'linew', 1.5); %Red line plot indicated by -r%

Ran using MATLAB R2019b

Upvotes: 1

Related Questions