ConnectionPath隐藏在子图的后面

编程入门 行业动态 更新时间:2024-10-25 13:20:56
本文介绍了ConnectionPath隐藏在子图的后面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想在两个对齐的子图上标记一条线.因此,我按照其他答案中的建议使用 matplotlib.patches.ConnectionPatch .它已经在其他示例中起作用,但在这里第二次,该线在第二个绘图区域被切断.

如何确保将ConnectionPatch绘制在前面?

我尝试使用zorder,但尚未找到解决方案.

来自matplotlib.patches的

导入ConnectionPatch导入matplotlib.pyplot作为pltxes=[-2, 0, 2]字段=[0, -10, 0]电位= [-20,0,20]图, axs = plt.subplots(2, 1, sharex=True)axs[0].plot(xes, field)axs [1] .plot(xes,势能)# 在两个图上划线_,ytop = axs [0] .get_ylim()ybot,_ = axs [1] .get_ylim()n_p_border = ConnectionPatch(xyA=(0., ytop), xyB=(0., ybot),coordsA='data', coordsB='data',轴A=轴[0],轴B=轴[1],lw=3)打印(n_p_border)斧头[0] .add_artist(n_p_border)

解决方案

您需要颠倒两个轴的角色.这也显示在

I want to mark a line over two aligned subplots. Therefore, I use matplotlib.patches.ConnectionPatch as suggested in other answers. It worked already in other examples, but here for the second time, the line just is cut off at the second plot area.

How do I assure that the ConnectionPatch is plotted in the front?

I tried playing around with zorder, but did not find a solution yet.

from matplotlib.patches import ConnectionPatch import matplotlib.pyplot as plt xes=[-2, 0, 2] field=[0, -10, 0] potential=[-20, 0, 20] fig, axs = plt.subplots(2, 1, sharex=True) axs[0].plot(xes, field) axs[1].plot(xes, potential) # line over both plots _, ytop = axs[0].get_ylim() ybot, _ = axs[1].get_ylim() n_p_border = ConnectionPatch(xyA=(0., ytop), xyB=(0., ybot), coordsA='data', coordsB='data', axesA=axs[0], axesB=axs[1], lw=3) print(n_p_border) axs[0].add_artist(n_p_border)

解决方案

You would need to inverse the role of the two axes. This is also shown in Drawing lines between two plots in Matplotlib.

from matplotlib.patches import ConnectionPatch import matplotlib.pyplot as plt xes=[-2, 0, 2] field=[0, -10, 0] potential=[-20, 0, 20] fig, axs = plt.subplots(2, 1, sharex=True) axs[0].plot(xes, field) axs[1].plot(xes, potential) # line over both plots _, ytop = axs[0].get_ylim() ybot, _ = axs[1].get_ylim() n_p_border = ConnectionPatch(xyA=(0., ybot), xyB=(0., ytop), coordsA='data', coordsB='data', axesA=axs[1], axesB=axs[0], lw=3) axs[1].add_artist(n_p_border) plt.show()

更多推荐

ConnectionPath隐藏在子图的后面

本文发布于:2023-11-23 04:36:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1620115.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:ConnectionPath

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!