在数据集“GDP 及构成.xls”中存放有从 2000 年到 2019 年我国的 GDP、第一产 业、第二产业、第三产业相关经济数据(单位:亿元),使用相关数据实现如下可视 化效果: 1) 使用画布子图 1、子图 2、子图 3 分别绘制 2017、2018、2019 年三大产业经济 占比情况;画布子图 4 绘制最近 10 年,三大产业的经济数据,其中横轴是年份, 纵轴是经济数据(单位:亿元),实现效果如图 1
时间: 2024-03-01 10:51:29 浏览: 10
很抱歉,作为一个 AI,我无法展示图片。但我可以提供实现这个可视化效果的代码,您可以在 Jupyter Notebook 或其他 Python 环境中运行并查看结果。
首先,需要导入相关的库:pandas、matplotlib 和 numpy。
```python
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
```
然后,读取数据集,并选取 2017 年、2018 年和 2019 年的数据,计算三大产业的经济占比。
```python
data = pd.read_excel('GDP 及构成.xls', sheet_name='Data')
data = data.set_index('年份')
industry_data = data.loc[[2017, 2018, 2019], ['第一产业', '第二产业', '第三产业']]
industry_data['总计'] = industry_data.sum(axis=1)
industry_data = industry_data.apply(lambda x: x / x['总计'], axis=1)
industry_data = industry_data.drop(columns=['总计'])
```
接着,绘制子图 1、子图 2 和子图 3,分别展示 2017 年、2018 年和 2019 年三大产业的经济占比。
```python
fig, (ax1, ax2, ax3) = plt.subplots(nrows=1, ncols=3, figsize=(15,5))
labels = ['第一产业', '第二产业', '第三产业']
colors = ['#ff9999','#66b3ff','#99ff99']
explode = (0.05, 0.05, 0.05)
ax1.pie(industry_data.loc[2017], colors=colors, labels=labels, autopct='%1.1f%%', startangle=90, pctdistance=0.85, explode=explode)
ax2.pie(industry_data.loc[2018], colors=colors, labels=labels, autopct='%1.1f%%', startangle=90, pctdistance=0.85, explode=explode)
ax3.pie(industry_data.loc[2019], colors=colors, labels=labels, autopct='%1.1f%%', startangle=90, pctdistance=0.85, explode=explode)
ax1.set_title('2017年三大产业经济占比')
ax2.set_title('2018年三大产业经济占比')
ax3.set_title('2019年三大产业经济占比')
plt.show()
```
最后,绘制子图 4,展示最近 10 年三大产业的经济数据。
```python
fig, ax4 = plt.subplots(figsize=(10,6))
x = data.index[-10:]
y1 = data['第一产业'][-10:]
y2 = data['第二产业'][-10:]
y3 = data['第三产业'][-10:]
ax4.plot(x, y1, label='第一产业')
ax4.plot(x, y2, label='第二产业')
ax4.plot(x, y3, label='第三产业')
ax4.set_title('最近10年三大产业的经济数据')
ax4.set_xlabel('年份')
ax4.set_ylabel('经济数据(单位:亿元)')
ax4.legend()
plt.show()
```
运行这段代码,就可以得到与问题描述中所给的效果类似的可视化结果。
相关推荐
![xls](https://img-home.csdnimg.cn/images/20210720083658.png)
![xls](https://img-home.csdnimg.cn/images/20210720083658.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)