数据可视化之matplotlib实战:plt.hist()函数 绘制直方图

    科技2022-07-10  179

    import matplotlib as mpl import matplotlib.pyplot as plt import numpy as np # 防止乱码 mpl.rcParams["font.sans-serif"] = ["SimHei"] mpl.rcParams["axes.unicode_minus"] = False # 生成数据 boxWeight = np.random.randint(0,10,1000) x = boxWeight # plot histogram bins = range(0,11,1) # 绘制图形 plt.hist(x,bins=bins, color="g", histtype="bar", rwidth=1, alpha=0.6) # 设置标签 plt.xlabel("箱子重量(KG)") plt.ylabel("销售个数(个)") plt.show()

    Processed: 0.034, SQL: 8