jupyternotebook如何画人口金字塔图
时间: 2023-09-03 07:15:27 浏览: 157
你可以使用Python中的matplotlib库来画人口金字塔图,具体方法如下:
```python
import matplotlib.pyplot as plt
# 定义男性和女性的人口数据
male_population = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
female_population = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]
# 画图
fig, ax = plt.subplots()
ax.barh(range(len(male_population)), male_population, align='center', height=0.5)
# 设置y轴标签和刻度
ax.set_yticks(range(len(male_population)))
ax.set_yticklabels(['10-14', '15-19', '20-24', '25-29', '30-34', '35-39', '40-44', '45-49', '50-54', '55-59'])
ax.invert_yaxis()
# 添加女性人口数据
ax.barh(range(len(female_population)), female_population, align='center', height=0.5)
# 设置标题、标签和网格线
ax.set_xlabel('人口数量')
ax.set_ylabel('年龄段')
ax.set_title('人口金字塔')
ax.grid(True)
plt.show()
```
这样就可以画出人口金字塔图了。
阅读全文
相关推荐












