Python 数据可视化 累积图
"""
Created on Tue Mar 9 20:16:57 2021
@author: dujidan
"""
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import norm
np.random.seed(0)
mu = 200
sigma = 25
n_bins = 50
x = np.random.normal(mu, sigma, size=100)
fig, ax = plt.subplots(figsize=(8, 4))
n, bins, patches = ax.hist(x, n_bins, density=True, histtype='step',
cumulative=True, label='Empirical')
y = norm.pdf(bins, mu, sigma).cumsum()
y /= y[-1]
ax.plot(bins, y, 'k--', linewidth=1.5, label='Theoretical')
ax.hist(x, bins=bins, density=True, histtype='step', cumulative=-1,
label='Reversed emp.')
ax.grid(True)
ax.legend(loc='right')
ax.set_title('Cumulative step histograms')
ax.set_xlabel('Annual rainfall (mm)')
ax.set_ylabel('Likelihood of occurrence')
plt.show()