
How to create shaded areas on graph which overlap
12 views (last 30 days)
Show older comments
Edoardo Bologna
on 23 Feb 2017
Answered: Star Strider
on 23 Feb 2017
I need to create multiple shaded areas delimited by horizontal lines in a graph. They should also be partly transparent. I am using area(X,Y,LEVEL) and then alpha(0.1) for transparency to ensure the overlap of the areas blend the two colours. I tried the following but once I add a second area, the first one automatically goes to the same LEVEL as the second. What I need is one part to be red, one to be blue and the overlapping part should be a mix (purple).
x2=([0,15]);
y2=([5.7,5.7]);
y3=[16.6,16.6];
y4=[11.4,11.4];
y5=[34.6,34.6];
II=area(x2,y5,11.4,'EdgeColor', 'none', 'FaceColor', 'r');
alpha(0.1)
hold on
I=area(x2,y3,5.7,'EdgeColor', 'none', 'FaceColor', 'b');
alpha(0.1);
hold off
0 Comments
Accepted Answer
Star Strider
on 23 Feb 2017
The patch function will do exactly what you want:
The Code —
x2=([0,15]);
y2=([5.7,5.7]);
y3=[16.6,16.6];
y4=[11.4,11.4];
y5=[34.6,34.6];
II=patch([x2 fliplr(x2)],[y4 fliplr(y5)], 'r');
alpha(0.1)
hold on
I=patch([x2 fliplr(x2)],[y2 fliplr(y3)], 'b');
alpha(0.1);
hold off
The Plot —

0 Comments
More Answers (0)
See Also
Categories
Find more on Surface and Mesh Plots 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!