根据表2和表3的数据绘制2018年1季度到2023年1季度之间GDP的同比和环比的双折线图,横轴是以季度为单位,纵轴是同比和环比
时间: 2024-03-09 21:50:03 浏览: 22
这里提供一个使用Python中的数据可视化库matplotlib绘制双折线图的示例代码,假设表2和表3的数据分别保存在csv文件中:
```python
import pandas as pd
import matplotlib.pyplot as plt
# 读取数据
df_tb = pd.read_csv('table2.csv', index_col=0) # 同比数据
df_hb = pd.read_csv('table3.csv', index_col=0) # 环比数据
# 取出2018年1季度到2023年1季度数据
df_tb = df_tb.loc['2018Q1':'2023Q1']
df_hb = df_hb.loc['2018Q1':'2023Q1']
# 创建图表
fig, ax = plt.subplots()
# 绘制同比和环比折线图
ax.plot(df_tb.index, df_tb['同比'], color='red', linestyle='solid', label='同比')
ax.plot(df_hb.index, df_hb['环比'], color='blue', linestyle='dashed', label='环比')
# 添加标签和标题
ax.set_xlabel('季度')
ax.set_ylabel('增长率')
ax.set_title('GDP同比和环比双折线图')
ax.legend()
# 显示图表
plt.show()
```
运行以上代码,即可得到一张GDP同比和环比的双折线图。需要注意的是,代码中的csv文件路径需要根据实际情况进行修改。