函數功能:在x軸上繪制定量數據的分布特征(用於連續數據,而柱狀圖用於離散數據)
調用簽名:plt.hist(x)
x:在x軸上繪制箱體的定量數據輸入值
代碼實現:
import matplotlib.pyplot as plt import numpy as np import matplotlib as mpl mpl.rcParams["font.sans-serif"]=["SimHei"] mpl.rcParams["axes.unicode_minus"]=False # 設置測試成績 boxWeight = np.random.randint(0, 10, 100) bins = range(0, 11, 1) plt.hist(boxWeight, bins=bins, color="g", histtype="bar", rwidth=1, alpha=0.6) plt.xlabel("箱子重量(kg)") plt.ylabel("銷售數量(個)") plt.show()

