您好,欢迎来到上海分类信息网
免费发信息

Matplotlib教程(直方图)——python可视化篇

2023-3-25 11:36:35发布5次查看ip:发布人:
源代码:
#导出matplotlib.pyplot,matplotlib.mlab 重命名为 plt,mlab
#导出numpy包重命名为np
import numpy as np
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
np.random.seed(19680801)
# 示例数据
mu = 100 # 分布均值
sigma = 15 # 分布标准偏差
x = mu + sigma * np.random.randn(437)
num_bins = 50
fig, ax = plt.subplots()
# 数据的直方图
n, bins, patches = ax.hist(x, num_bins, normed=1)
# 添加一个“最适合”行
y = mlab.normpdf(bins, mu, sigma)
ax.plot(bins, y, '--')
ax.set_xlabel('smarts')
ax.set_ylabel('probability density')
ax.set_title(r'histogram of iq: $mu=100$, $sigma=15$')
# 调整间距,以防止ylabel剪辑
fig.tight_layout()
plt.show()
该用户其它信息

VIP推荐

上海分类信息网-上海免费发布信息-上海新闻网