Borrar filtros
Borrar filtros

Shade area under a plot with MATLAB

60 visualizaciones (últimos 30 días)
Gianmarco Broilo
Gianmarco Broilo el 17 de Nov. de 2021
Respondida: DGM el 18 de Nov. de 2021
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')

Respuestas (1)

DGM
DGM el 18 de Nov. de 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])

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by