通过pandas绘制 人均收入 的折线图和柱状图(在一张图上),此外,单独绘制饼状图和箱体图。
时间: 2024-05-02 19:18:18 浏览: 80
假设有以下数据:
```
import pandas as pd
import matplotlib.pyplot as plt
data = {'year': [2010, 2011, 2012, 2013, 2014, 2015, 2016],
'income': [5000, 5500, 6000, 6500, 7000, 7500, 8000]}
df = pd.DataFrame(data)
```
人均收入折线图和柱状图:
```
fig, ax = plt.subplots()
ax.plot(df['year'], df['income'], marker='o')
ax.bar(df['year'], df['income'])
ax.set_xlabel('Year')
ax.set_ylabel('Income')
ax.set_title('Per Capita Income')
plt.show()
```
饼状图:
```
fig, ax = plt.subplots()
ax.pie(df['income'], labels=df['year'], autopct='%1.1f%%')
ax.set_title('Per Capita Income')
plt.show()
```
箱体图:
```
fig, ax = plt.subplots()
ax.boxplot(df['income'], vert=False)
ax.set_yticklabels(['Income'])
ax.set_title('Per Capita Income')
plt.show()
```
阅读全文