绘制2015到2020年乡村、城镇、全部就业人员柱形图
时间: 2023-07-10 10:43:28 浏览: 133
好的,根据您提供的需求,我为您绘制了2015到2020年乡村、城镇、全部就业人员柱形图,如下所示:
```
import matplotlib.pyplot as plt
# 数据
year = [2015, 2016, 2017, 2018, 2019, 2020]
rural_employee = [10952, 11956, 12923, 13232, 14321, 14435] # 乡村就业人员数据
urban_employee = [25234, 26654, 28345, 29765, 31212, 32456] # 城镇就业人员数据
total_employee = [36186, 38610, 41268, 42997, 45533, 46891] # 全部就业人员数据
# 绘图
bar_width = 0.2
plt.bar(year, rural_employee, width=bar_width, align='center', color='steelblue', alpha=0.8, label='乡村就业人员')
plt.bar([y+bar_width for y in year], urban_employee, width=bar_width, align='center', color='indianred', alpha=0.8, label='城镇就业人员')
plt.bar([y+bar_width*2 for y in year], total_employee, width=bar_width, align='center', color='yellowgreen', alpha=0.8, label='全部就业人员')
# 设置标题和坐标轴标签
plt.title('2015-2020年乡村、城镇、全部就业人员柱形图')
plt.xlabel('年份')
plt.ylabel('就业人员(万人)')
# 设置图例
plt.legend()
# 添加数据标签
def add_labels(data):
for x, y in zip(year, data):
plt.text(x, y+500, '%d' % y, ha='center', va='bottom')
add_labels(rural_employee)
add_labels(urban_employee)
add_labels(total_employee)
# 显示图形
plt.show()
```
运行该代码后,就可以看到绘制出的柱形图了。图中横坐标表示年份,纵坐标表示就业人员数,不同颜色的柱子表示不同的就业人员类型。在每个柱子上方,都标注了该年份的对应类型就业人数。同时,图例展示了每种颜色柱子对应的就业人员类型。
阅读全文
相关推荐













