python - 如何在从另一个子图中放大的子图之间创建连接线?
问题描述
我已经能够创建一个放大的子图,以在一个 1990 年到 2019 年的图中描绘 1990 年到 2019 年的值。我想添加连接线,如附图中红色所示:
我用来获取上图的代码如下:
fig, ax = plt.subplots(figsize=(20, 12))
ax = df.plot(kind="area", stacked=True, ax=ax,
color=colors)
ax.set_ylabel("TWh")
ax.set_title(
"Global Energy Consumption from 1800 to 2019 \nSource: BP Statistical Review of World Energy 2021")
ax.legend(bbox_to_anchor=(1, 1))
# Create a plot for zooming in
# left, bottom, width, height
ax_new = fig.add_axes([0.4, 0.5, 0.3, 0.3])
ax_new = df.loc[1990:].plot(kind="area", stacked=True, ax=ax_new, color=colors)
ax_new.set_ylabel("TWh")
ax_new.set_title("1990 to 2019")
ax_new.legend("", frameon=False)
# plt.tight_layout()
plt.savefig("Global energy consumption", dpi=300)
plt.show()
如何在两个子图中的 xaxes 之间添加连接线?
解决方案
推荐阅读
- android - 如何以编程方式检查 Android 平板电脑是否具有 simcard 功能?
- angular - Angular - HostListener 指令和传递值
- java - Spring Mail 集成 - 我如何将 org.springframework.messaging.Message 转换为 javax.mail.internet.MimeMessage
- laravel - 我应该如何在仅开发环境中制作 DebugPage?
- c++ - unique_ptr 拥有的对象的索引运算符
- windows - Set-Partition -IsHidden $true 也隐藏磁盘上的其他分区
- java - Java算法将时间分成递减部分
- mysql - 有人可以帮我在 Siddhi 流处理器中解决这个问题吗?
- javascript - 仅在 Opera 浏览器中内存消耗急剧增加
- python - 限制 django 视图上的内容