如何用jupyternotebook画人口金字塔图
时间: 2023-10-08 11:14:45 浏览: 106
您可以使用Python中的Matplotlib库来画人口金字塔图。以下是一个简单的代码示例:
```python
import matplotlib.pyplot as plt
# 设定数据
age_groups = ['0-4', '5-9', '10-14', '15-19', '20-24', '25-29', '30-34', '35-39', '40-44', '45-49', '50-54', '55-59', '60-64', '65-69', '70-74', '75-79', '80-84', '85+']
male_pop = [100, 202, 300, 400, 550, 650, 700, 800, 900, 950, 1000, 800, 700, 600, 500, 200, 100, 50]
female_pop = [80, 200, 280, 370, 500, 620, 650, 750, 880, 920, 800, 700, 600, 500, 300, 100, 50, 20]
# 画图
fig, ax = plt.subplots()
ax.barh(age_groups, male_pop, align='center', height=0.5, color='blue')
ax.barh(age_groups, [-i for i in female_pop], align='center', height=0.5, color='pink')
ax.set_xlabel('Population')
ax.set_ylabel('Age Groups')
ax.set_title('Population Pyramid')
# 显示图像
plt.show()
```
您可以自行替换数据和调整绘图参数来满足您的需求。希望对您有所帮助!
阅读全文
相关推荐













