Shade area under a plot with MATLAB
14 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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')

0 Kommentare
Antworten (1)
DGM
am 18 Nov. 2021
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])
0 Kommentare
Siehe auch
Kategorien
Mehr zu Surface and Mesh Plots finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
