How to change the color of a graph only in a particular section?
22 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
M G
am 17 Mär. 2011
Beantwortet: Korosh Agha Mohammad Ghasemi
am 7 Dez. 2020
Hey all,
I was just wondering if there is a way to change a particular part of a plot to another color? Suppose we have a plotted signal in BLUE and we wannan show the main response (let's say with the highest amplitude) in RED.
0 Kommentare
Akzeptierte Antwort
Jan
am 17 Mär. 2011
You can draw different lines.
t = 0:0.02:4*pi;
y = sin(t);
index = (y >= 0);
plot(t, y, 'b');
plot(t(index), y(index), 'r');
1 Kommentar
Matt Tearle
am 22 Mär. 2011
A nice trick to remove points graphically is to set them to NaN. Eg
t = 0:0.02:4*pi;
y = sin(t);
z1 = y;
z1(y>=0) = NaN;
z2 = y;
z2(y<0) = NaN;
plot(t,z1,'b',t,z2,'r')
And while I'm here, I might as well peddle my wares: http://www.mathworks.com/matlabcentral/fileexchange/30423-conditionally-colored-line-plot
Weitere Antworten (1)
Korosh Agha Mohammad Ghasemi
am 7 Dez. 2020
%https://zil.ink/korosh -------- Ways to contact me ----------
% Korosh Agha Mohammad Ghasemi !
% Chemical Engineering at Shiraz University
x=linspace(0,2,100);
figure;
for a=[0.1 0.5 1 2 4]
y=x.^a; %The function is hypothetical
if a == 0.1 %Any color can be substituted
y=x.^a;
plot(x,y,'k') %Now choose the color
hold on
elseif a == 0.5
y=x.^a;
plot(x,y,'b') %Now choose the color
hold on
elseif a==1
y=x.^a;
plot(x,y,'g') %Now choose the color
hold on
elseif a==2
y=x.^a;
plot(x,y,'r') %Now choose the color
hold on
elseif a==4
y=x.^a;
plot(x,y,'y') %Now choose the color
hold on
grid on
end
end
0 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!