Skip to content Skip to sidebar Skip to footer

Use Fill_between In Python To Shade A Sub Area Of A Density Curve

I would like to Fill_Between a sub section of a normal distribution, say the left 5%tile. import numpy as np import matplotlib.pyplot as plt from scipy import stats as stats plt.st

Solution 1:

As commented, you need to use plt.fill_between instead of plt_fill_between. When doing so the output looks like this which seems to be exactly what you're looking for.

import numpy as np
import matplotlib.pyplot as plt
from scipy import stats as stats
plt.style.use('ggplot')
mean=1000
std=250
x=np.linspace(mean-3*std, mean+3*std,1000)
iq=stats.norm(mean,std)
plt.plot(x,iq.pdf(x),'b')

px=np.arange(0,500,10)
plt.fill_between(px,iq.pdf(px),color='r')

plt.show()

enter image description here


Solution 2:

You only use the x values from 0 to 500 in your np.arange if you want to go to 2000 write:

px=np.arange(0,2000,10)
plt.fill_between(px,iq.pdf(px),color='r')

Post a Comment for "Use Fill_between In Python To Shade A Sub Area Of A Density Curve"