【代码模版】matplotlib绘制带有子图的二轴折线图

# 准备画图
import matplotlib.pyplot as plt
%matplotlib inline
# 指定默认风格
plt.style.use('fivethirtyeight')  # 该风格可以查阅官方文档并修改
# 设置布局
fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(nrows=2, ncols=2, figsize = (10,10))  # 2行2列,第一行的2个图是ax1和ax2;第二行的两个图是ax3和ax4
fig.autofmt_xdate(rotation = 45)

# 实际气温值
ax1.plot(dates, origin_data['actual'])  # 1行1列图片的x与y值传入
ax1.set_xlabel(''); ax1.set_ylabel('Temperature'); ax1.set_title('Max Temp')  # x轴/y轴/图片名称

# 昨天
ax2.plot(dates, origin_data['temp_1'])
ax2.set_xlabel(''); ax2.set_ylabel('Temperature'); ax2.set_title('Previous Max Temp')

# 前天
ax3.plot(dates, origin_data['temp_2'])
ax3.set_xlabel('Date'); ax3.set_ylabel('Temperature'); ax3.set_title('Two Days Prior Max Temp')

# 我的逗逼朋友
ax4.plot(dates, origin_data['friend'])
ax4.set_xlabel('Date'); ax4.set_ylabel('Temperature'); ax4.set_title('Friend Estimate')

plt.tight_layout(pad=2)
发布了22 篇原创文章 · 获赞 0 · 访问量 933

猜你喜欢

转载自blog.csdn.net/weixin_44680262/article/details/104608591
今日推荐