其他分享
首页 > 其他分享> > Matplotlib库学习笔记(8) pyplot 绘制直方图

Matplotlib库学习笔记(8) pyplot 绘制直方图

作者:互联网

参考链接: Matplotlib官网
参考链接: Python数据分析与展示
参考链接: Matplotlib官网 API Overview

实验代码:

# 绘制直方图
import numpy as np
import matplotlib.pyplot as plt

np.random.seed(20200910)
mu, sigma = 100,20 # 设置随机数分均值和标准差
a = np.random.normal(mu, sigma, size=100) # 产生100个随机数

# histtype{'bar', 'barstacked', 'step', 'stepfilled'}, default: 'bar'
# bins是直方图中直方的数量
plt.hist(a,bins=20,\
    # normed=1 , # 这个参数已经删除了,用density替换了
    density=False, # density=True, False,
    histtype='stepfilled',facecolor='b',alpha=0.9)

plt.title(\
    r'直方图(Histogram) :$\mu={0},\sigma={1}$'.format(mu,sigma),\
    fontproperties='SimHei',\
    fontsize=25)

plt.show()

执行结果展示:
在这里插入图片描述

标签:plt,density,pyplot,Matplotlib,mu,直方图,sigma
来源: https://blog.csdn.net/m0_46653437/article/details/110310379