Is there a way to make a plot of a line with different colors?
4 views (last 30 days)
Show older comments
Floyd Haylock
on 17 Feb 2014
Commented: Floyd Haylock
on 17 Feb 2014
If I have y = rand(100,1), can I plot y such that the portions of the line that are greater than or equal to 0.5 is plot in red while portions lying below 0.5 is plot in black?
0 Comments
Accepted Answer
Jos (10584)
on 17 Feb 2014
To plot lines as well:
% some data
x = linspace(0,1,100);
y = rand(1,length(x));
tf = y >= 0.5 ;
y2 = y ; y2(~tf) = nan ;
ph = plot(x,y,'k.-',x,y2,'ro-')
set(ph(2),'linewidth',2)
3 Comments
More Answers (0)
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!