python 直方图
python可以调用hist方法绘制直方图。
import matplotlib.pyplot as plt
import numpy as np;
plt.rcParams["font.family"]=["SimHei"] # 确保图中中文字体正确显示
x=[0.1,0.2,0.3,0.4,0.5,0.6,0.1,0.2,0.2,0.2]
plt.xlabel('满意程度')
plt.ylabel('频数')
plt.title('xxx标题',fontsize=18)
plt.hist(x,6)
plt.show()
调用方法:plt.hist(x, bins=6)
参数说明:
x:指定要绘制直方图的数据;
bins:指定直方图条形的个数;
x=[0.1,0.2,0.3,0.4,0.5,0.6,0.1,0.2,0.2,0.2]
该方法是统计0.1的个数,0.2的个数等等