考慮以下簡單示例:
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot()
ax.plot([0],[0])
ax.grid()
ax.set_xlim([0,10])
ax.set_ylim([0,10])
ax.annotate("", (2, 1), (4, 1), arrowprops={'arrowstyle':'<->'})
plt.show()
因此,使用ax.annotate,我想從點 (x=2, y=1) 到點 (x=4, y=1) 繪制一個箭頭;然而輸出是這樣的:

如螢屏截圖所示,箭頭并不完全指向端點 (x=2, y=1) 和 (x=4, y=1) - 相反,有少量空白“填充”或“利潤”。
我怎樣才能讓箭頭端點(箭頭的尖端)與指定的端點完全對齊?為了明確起見,我嘗試編輯上面的影像,并手動繪制箭頭(在讀取中)我希望它們所在的位置:

感謝@JodyKlymak 的評論,我查看了
So, let me reformulate - is it possible to get "correct" full-length arrow, with the default left-right arrow from ax.annotate (the one that looks just like a line, and not as a thicker filled surface)?
uj5u.com熱心網友回復:
好的,我終于明白了;我從
uj5u.com熱心網友回復:
正如您所提到的,不可能將收縮與 'arrowstyle':'<->' 一起使用。但是,您可以使用 ax.annotate("", (2, 1), (4, 1), arrowprops={'shrink': 0}) 的副本,如下所示:
ax.annotate("", (2, 1), (4, 1), arrowprops={'width': 0.01,'facecolor':'black','shrink': 0})
ax.annotate("", (4, 1), (2, 1), arrowprops={'width': 0.01,'facecolor':'black','shrink': 0})
這導致:

轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/375381.html
標籤:python matplotlib
