How to change color in a plot?
255 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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] ?
0 Kommentare
Antworten (1)
Brendan Hamm
am 2 Jun. 2015
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.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Annotations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!