How to change color in a plot?

514 次查看(过去 30 天)
Nimrod Daniel
Nimrod Daniel 2015-6-2
Hello,
I have a plot with 4 different colors, and I want to change the green (light green) to deep green, so it would be like: plot(x,y,'color',[0 0.7 0])
In the main file I have:
if m == 1 color='.blue'; else if m == 2 color='.red'; else if m == 3 color='.black'; else if m == 4 color='.green'; end; end; end; end;
And in another function I have (the other function gets color, of course) : plot(xloc_est,yloc_est,color); % plot the filtered data
My simple question is what should I change in order to change the light green to [0 0.7 0] ?

回答(1 个)

Brendan Hamm
Brendan Hamm 2015-6-2
One thing you could do is just change the ColorOrder property of the axes itself:
f = figure;
colors = [0 0 0.7; 0.7 0 0; 0 0 0; 0 0.7 0 0]; % b,r,k,g
a = axes('ColorOrder',colors)
% plot your lines and they will be plotted with these colors in order.
plot(x,y);
hold on
plot(x2,y,2);
Then plot your other lines ...
Your other option is to change with a single plot the way you showed:
plot(x,y,'Color',[0 0.7 0]);
which could be accomplished in your loop:
if m == 1
color = 'b';
elseif m == 2
color = 'r';
elseif m == 3
color == 'k'
elseif m == 4
color == [0 0.7 0];
end
plot(x,y,'Color',color);
Avoid using nested if statements as they are not needed. The elseif is a single keyword.

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by