matplotlib hist
hist()
绘制直方图,并根据提供的参数调整直方图的输出外观。
语法
根据需要选择并设定参数:
hist(x, bins=None, range=None, density=False, weights=None, cumulative=False, bottom=None, histtype=’bar’, align=’mid’, orientation=’vertical’, rwidth=None, log=False, color=None, label=None, stacked=False, \*, data=None, \*\*kwargs)
实例
随机生成1000个正太分布的数据x,并将x绘制为直方图:
import matplotlib.pyplot as plt
import numpy as np
# 生成随机数
a=100
b=15
x=a+b*np.random.randn(1000)
# 绘图并显示
num_bins=20
n,bins,patches=plt.hist(x,num_bins,rwidth=0.9,facecolor='#607c8e',alpha=0.5)
plt.show()


关注公众号,获取一手资讯
“ matplotlib hist ” comments 0