Python ConnectionPath隐藏在子地块后面

Python ConnectionPath隐藏在子地块后面,python,matplotlib,Python,Matplotlib,我想在两个对齐的子地块上画一条线。因此,我使用了其他答案中建议的matplotlib.patches.ConnectionPatch。它已经在其他例子中起作用了,但这是第二次,在第二个绘图区域,直线被切断 如何确保在前面绘制ConnectionPatch? 我试着和佐德玩,但还没有找到解决办法 您需要反转两个轴的角色。这也显示在中 哦,太简单了。这个想法就是在最后绘制的轴上绘制连接路径。谢谢 from matplotlib.patches import ConnectionPatch impo

我想在两个对齐的子地块上画一条线。因此,我使用了其他答案中建议的
matplotlib.patches.ConnectionPatch
。它已经在其他例子中起作用了,但这是第二次,在第二个绘图区域,直线被切断

如何确保在前面绘制ConnectionPatch?

我试着和佐德玩,但还没有找到解决办法


您需要反转两个轴的角色。这也显示在中


哦,太简单了。这个想法就是在最后绘制的轴上绘制
连接路径。谢谢
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)
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()