How to color an area at plot surface...
45 views (last 30 days)
Show older comments
Masoud Ghanbari on 17 Apr 2013
How can i color the area between 2 functions like
Thomas on 18 Apr 2013
I found a better way... try
patch([x x(end:-1:1)], [f g(end:-1:1)],'y')
This sets up x=1...10, g=x² and f=x²+1 and then plots the area between the curves as a yellow polygon/patch. Compare the matlab help for patch.
Here i simply draw all points forf first in positive x direction and then jump to the last point of g and draw the points of g backwards from x=10...1. All in all a complete polygon. Btw, 'y' is the color yellow.
More Answers (3)
Thomas on 17 Apr 2013
You could use sth like
and then select f's fill color to be the backgroud color.
Of coures this only works as long as f<g for all x.
If this is not the case you could first do
upperCurve = max(f,g)
lowerCurve = min(f,g)
and then plot upperCurve and lowerCurve as stated above. If they are sufficiently high-res compared to your plot resolution it might be sufficient, however it wouldn't be "clean". Maybe there is another solution anyone can bring up...
Muruganandham Subramanian on 18 Apr 2013
x=[1 2 3 4 5];
Do you expecting like this?
Find more on Polygons 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!