Pyplot 直方图条形图如何解释?(Matplotlib)


若要绘制具有不同条形图的直方图,我们可以采取以下步骤-

  • 设置图形大小并调整子图之间和周围的填充。

  • 编制要绘制到直方图中的数据列表。

  • 向当前图形中添加子图,nrows=1, ncols=3index=1

  • 绘制具有 data; bins 的直方图是一个数字。

  • 向当前图形中添加子图 nrows=1, ncols=3index=2

  • 使用 data; bins 绘制直方图是一个数组。

  • 向当前图形中添加子图, nrows=1, ncols=3index=3

  • 使用 data, bins 绘制直方图是一个字符串。

示例

import matplotlib.pyplot as plt

plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True

data = [1, 3, 1, 4, 7, 1, 3, 5, 4, 6, 5]

plt.subplot(131)
plt.hist(data, bins=len(data))

plt.subplot(132)
plt.hist(data, bins=[1, 3, 5, 7])

plt.subplot(133)
plt.hist(data, bins='stone')

plt.show()

输出

更新于: 09-Aug-2021

221 查看

开启您的职业生涯

完成课程后获得认证

开始
广告
© . All rights reserved.