【数据分析&数据挖掘】薪资分布直方图

 1 # 某公司 员工的薪资水平 在[3500,35000] 之间,而且公司共有55个人
 2 # 让大家 自己自定分组,来查看大部分员工的薪水水平,来给公司做薪水指导。
 3 import matplotlib.pyplot as plt
 4 import numpy as np
 5 
 6 plt.figure()
 7 
 8 plt.rcParams['font.sans-serif'] = 'SimHei'
 9 plt.rcParams['axes.unicode_minus'] = False
10 
11 data = np.random.randint(low=3500, high=35000, size=33)
12 group_num = 10
13 ptp = data.max() - data.min()
14 step = int(np.ceil(ptp / group_num))
15 bins = np.arange(data.min(), data.max() + step, step)
16 plt.hist(data, bins=bins, color="#EEE685", edgecolor="#8B864E")
17 
18 plt.xlabel("薪资(元)")
19 plt.ylabel("人数(个)")
20 plt.title("薪资分布直方图")
21 
22 xticks = np.arange(3500, 35001, 3150)
23 plt.xticks(bins, xticks)
24 yticks = np.arange(0, 10)
25 plt.yticks(yticks)
26 plt.grid(True,axis="y",alpha=0.2)
27 plt.show()
28 
29 
30 # 某公司 员工的薪资水平 在[3500,35000] 之间,而且公司共有55个人
31 # 让大家 自己自定分组,来查看大部分员工的薪水水平,来给公司做薪水指导。

原文地址:https://www.cnblogs.com/Tree0108/p/12115948.html