フィルターのクリア

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 Center および File ExchangeAnnotations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by