As an example, I attach the code to draw the graph of a normal distribution. I have managed to fill its entire interior with color, but what I really want is to fill only from the extreme left to the ordered one marked with the letter "a".
import pandas as pd
from scipy import stats
import matplotlib.pyplot as plt # importando matplotlib
# Graficando Normal
etiquetas = "Z"
x_pos = [1]
mu, sigma = 0, 1 # media y desvio estandar
normal = stats.norm(mu, sigma)
x = np.linspace(normal.ppf(0.01),
normal.ppf(0.99), 100) # función e densidad de probabilidad
fp = normal.pdf(x) # Función de Probabilidad
plt.plot(x, fp)
plt.xticks(x_pos, etiquetas)
plt.fill_between(x , fp, facecolor="green", alpha= 0.2)
plt.vlines(1, ymin= 0, ymax= 0.25, color = "blue", linestyles ="--")
plt.title('Distribución Normal')
plt.ylabel('probabilidad')
plt.xlabel('valores')
plt.show()
I will appreciate your suggestions.
You must use the argument
where
ofmatplotlib.pyplot.fill_between
to indicate a condition based on the values of the axisx
,y
or both:If you want to fill between two values of x, since you use NumPy you should do: