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

2 Ansichten (letzte 30 Tage)
xiaobo wu
xiaobo wu am 10 Sep. 2015
Beantwortet: Walter Roberson am 10 Sep. 2015
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?

Antworten (1)

Walter Roberson
Walter Roberson am 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

Kategorien

Mehr zu Line Plots finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by