You can use plt.fill_between:
import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
plt.style.use('ggplot')
mean = 100
std = 16
x = np.linspace(mean - 5 * std, mean + 5 * std, 1000)
iq = stats.norm(mean, std)
plt.plot(x, iq.pdf(x), 'r-', lw=3)
colors = ['c', 'r', 'b', 'g', ]
colors = colors + list(reversed(colors))
for i, color in zip(range(-4, 4), colors):
low = mean + i * std
high = mean + (i + 1) * std
px = x[np.logical_and(x >= low, x <= high)]
plt.fill_between(
px,
iq.pdf(px),
color=color,
alpha=0.5,
linewidth=0,
)
plt.tight_layout()
plt.savefig('test.png', dpi=300)

source
share