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

2 vues (au cours des 30 derniers jours)
xiaobo wu
xiaobo wu le 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?

Réponses (1)

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

Catégories

En savoir plus sur Line Plots dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by