How to change the color of a graph only in a particular section?

Illustration
Mariahernandez - 2020-08-27T11:24:33+00:00
Question: How to change the color of a graph only in a particular section?

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.

Expert Answer

Profile picture of Prashant Kumar Prashant Kumar answered . 2025-11-20

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');


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!