필터 지우기
필터 지우기

How to change color in a plot?

조회 수: 255 (최근 30일)
Nimrod Daniel
Nimrod Daniel 2015년 6월 2일
답변: Brendan Hamm 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에서 Annotations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by