How to set the background color for the selected data in the plot?

1 view (last 30 days)
For example, Here is:
t=0:0.1:100;
x=sin(t);
plot(t,x)
So the plot will show a sin wave.
And now, I select the sin data between t=0:0.1:20, and decide to set the background color as red for the selected data between t=0:0.1:20.
So how to do this in the same plot?
Besides, how to do if I want to change the selected data color to red in the same plot?

Answers (1)

Walter Roberson
Walter Roberson on 10 Sep 2015
To set an area's background color, first determine the boundaries of the region and then use fill()
plot() uses line objects, and those can only have one color per line.
There are a number of routines in the File Exchange that allow you to control color along a line. See http://www.mathworks.com/matlabcentral/answers/100246-how-do-i-create-a-2-d-or-3-d-line-that-changes-colors-along-the-data-points for one discussion

Tags

Community Treasure Hunt

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

Start Hunting!