Matplotlib is hiring a Research Software Engineering Fellow! See discourse for details. Apply by January 3, 2020

Version 3.1.1
matplotlib
Fork me on GitHub

目录

Related Topics

直方图函数的不同演示 histtype 设置

  • 带有颜色填充的阶跃曲线的柱状图。
  • 带自定义和不等箱宽的柱状图。

选择不同的仓位计数和大小会显著影响直方图的形状。Astropy文档有一个关于如何选择这些参数的重要部分:http://docs.astropy.org/en/stable/visualization/histogram.html

直方图函数的不同演示 histtype 设置
import numpy as np
import matplotlib.pyplot as plt

np.random.seed(19680801)

mu = 200
sigma = 25
x = np.random.normal(mu, sigma, size=100)

fig, (ax0, ax1) = plt.subplots(ncols=2, figsize=(8, 4))

ax0.hist(x, 20, density=True, histtype='stepfilled', facecolor='g', alpha=0.75)
ax0.set_title('stepfilled')

# Create a histogram by providing the bin edges (unequally spaced).
bins = [100, 150, 180, 195, 205, 220, 250, 300]
ax1.hist(x, bins, density=True, histtype='bar', rwidth=0.8)
ax1.set_title('unequal bins')

fig.tight_layout()
plt.show()