正如鏈接問題中的註釋(Drawing lines between two plots in Matplotlib)所示,您應該使用ConnectionPatch
連接圖。關於這個ConnectionPatch
的好處不僅在於它很容易實現,而且它將隨數據一起移動和放大。
這是一個如何使用它的例子。
import matplotlib.pyplot as plt
from matplotlib.patches import ConnectionPatch
import numpy as np
fig, (ax1, ax2) = plt.subplots(1,2, sharex=True, sharey=True)
x,y = np.arange(23), np.random.randint(0,10, size=23)
x=np.sort(x)
i = 10
ax1.plot(x,y, marker="s", linestyle="-.", c="r")
ax2.plot(x,y, marker="o", linestyle="", c="b")
con = ConnectionPatch(xyA=(x[i],y[i]), xyB=(x[i],y[i]),
coordsA="data", coordsB="data",
axesA=ax2, axesB=ax1, arrowstyle="-")
ax2.add_artist(con)
plt.show()
通過縮放意味着您可以使用matplotlib窗口中提供的工具進行交互式縮放,或者是否以編程方式縮放? – ImportanceOfBeingErnest
使用matplotlib繪圖工具欄中提供的工具。 – floflo29