Shade area under a plot with MATLAB

11 ビュー (過去 30 日間)
Gianmarco Broilo
Gianmarco Broilo 2021 年 11 月 17 日
回答済み: DGM 2021 年 11 月 18 日
I am trying to shade the area under a curve on MATLAB, this is the code I have:
The problem is that is shading only the negative part of the graph, not its symmetric positive part..
plot(Navg(2:end),closestapproach(2:end)./1e3-2634,'k')
hold on
plot(serrN_2000,closestapproach(2:end)./1e3-2634,'b');
hold on
plot(-serrN_2000,closestapproach(2:end)./1e3-2634,'b');
hold on
plot(B,closestapproach(2:end)./1e3-2634,'r');
hold on
plot(-B,closestapproach(2:end)./1e3-2634,'r');
shade(B,closestapproach(2:end)./1e3-2634,'r')
hold on
shade(serrN_2000,closestapproach(2:end)./1e3-2634,'b')
hold on
shade(-B,closestapproach(2:end)./1e3-2634,'r')
hold on
shade(-serrN_2000,closestapproach(2:end)./1e3-2634,'b')
title('Vertical electron density profile and uncertainty')
ylabel('Altitude [km]')
xlabel('Electron density [cm-3]')
xline(0)
legend('Average profile','1*\sigma','3*\sigma')

回答 (1 件)

DGM
DGM 2021 年 11 月 18 日
I don't know what shade() you're using, since it's not part of MATLAB. Otherwise, you can do something with patch objects:
y = linspace(0,1,100);
x1 = (1+0.1*randn(1,100)).*(1-y).^0.25;
x2 = 2*(1+0.1*randn(1,100)).*(1-y).^0.25;
hold on
patch([x2 fliplr(-x2)],[y fliplr(y)],'r','facealpha',0.3,'edgecolor','r');
patch([x1 fliplr(-x1)],[y fliplr(y)],'b','facealpha',0.3,'edgecolor','b');
xlim([-2.5 2.5])

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by