Matplotlib 直方图


章节


直方图是一种非常常见的图表类型,尤其在概率统计很常用,是正态分布、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

posted @ 2019-11-14 10:31  吴吃辣  阅读(129)  评论(0编辑  收藏  举报