章节


直方图是一种非常常见的图表类型,尤其在概率统计很常用,是正态分布、t分布等各种分布的基础。直方图使用hist()方法绘制。

示例

生成一个随机的连续数据,包含1000个条目,将这些数据划分为10个等分,根据其频率绘制图表。

# 导入numpy库与matplotlib.pyplot库
import numpy as np
import matplotlib.pyplot as plt

# 准备数据
x = np.random.randn(1000)

# 绘制图形
plt.title("Histogram")
plt.xlabel("Random Data")
plt.ylabel("Frequency")
plt.hist(x, 10)

# 显示
plt.show()

输出

Matplotlib 直方图

相关文章:

  • 2021-06-21
  • 2022-12-23
  • 2021-07-30
  • 2022-01-07
  • 2022-01-07
  • 2021-07-17
  • 2022-01-24
  • 2022-12-23
猜你喜欢
  • 2022-01-09
  • 2021-10-01
  • 2022-01-13
  • 2021-07-09
  • 2022-12-23
  • 2021-11-11
  • 2022-01-07
相关资源
相似解决方案