我想在两个对齐的子图上画一条线。因此,我使用其他答案中建议的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)
你需要反转两轴的作用。这也显示在Drawing lines between two plots in Matplotlib中。你知道吗
相关问题 更多 >
编程相关推荐