How to plot the area between the 2 curves with transparency 50% ?

6 次查看(过去 30 天)
y = [0;2;4;8;12;15;19;21;23;26;29;32;36;40;43;45];
h=[-0.4270; -0.3210;-0.3600;-0.2967;-0.1400;-0.0876;-0.2430;-0.4170;-0.9860;-0.7460;-0.6430;-0.5470;-0.4300;-0.3210;-0.2500;-0.2890];
l=[-0.2200;-0.1060;-0.1150;-0.0640;0.0550;0.0870;-0.0309;-0.2110;-0.7630;-0.5440;-0.4410;-0.3650;-0.2290;-0.1160;-0.0590;-0.0946];
plot(y,h,'b');hold on;
plot(y,l,'b');

采纳的回答

Star Strider
Star Strider 2022-2-13
y = [0;2;4;8;12;15;19;21;23;26;29;32;36;40;43;45];
h=[-0.4270; -0.3210;-0.3600;-0.2967;-0.1400;-0.0876;-0.2430;-0.4170;-0.9860;-0.7460;-0.6430;-0.5470;-0.4300;-0.3210;-0.2500;-0.2890];
l=[-0.2200;-0.1060;-0.1150;-0.0640;0.0550;0.0870;-0.0309;-0.2110;-0.7630;-0.5440;-0.4410;-0.3650;-0.2290;-0.1160;-0.0590;-0.0946];
figure
plot(y,h,'b')
hold on
plot(y,l,'b')
patch([y; flipud(y)], [h; flipud(l)], 'r', 'FaceAlpha',0.5, 'EdgeColor','none')
hold off
The approach is to create a closed, continuous curve for patch to fill. That is the reason for the flip (here flipud) calls.
See the docujmentation on patch for more information on it.
.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

标签

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by