我正在嘗試使用annotate包在圖中插??入箭頭(括號),但我無法弄清楚輸入引數的含義。我閱讀了檔案,但仍然不確定如何控制箭頭。這是一個示例起點:
import matplotlib.pyplot as pl
import numpy as np
fig = pl.figure(figsize=(3.25, 2.5))
ax0 = fig.add_subplot(111)
x, y = np.arange(10), np.arange(10) * -1
for offset in range(5):
ax0.plot(x offset, y, lw=1)
# add annotation arrow
bbox = dict(facecolor="w",
alpha=0.95,
ls="None",
boxstyle="round",
pad=0.1)
ax0.annotate(text="Example",
xy=(7.5, -5),
xytext=(0, -9),
arrowprops=dict(arrowstyle="-[",
linewidth=1,
connectionstyle="arc,armA=90,angleA=0,angleB=-40,armB=85,rad=0"),
verticalalignment="bottom",
horizontalalignment="left",
fontsize=8,
bbox=bbox)
fig.show()
我希望括號跨越所有繪制線的寬度(好像說“這些”線是注釋所指的),但我不知道如何更改括號寬度。
另一個問題是解釋armA和armB(箭頭線目前看起來很難看)。我知道這些是指線段的長度,但我無法弄清楚單位是什么(像素?),更不用說如何自動生成它們的長度了。
您能否提供有關如何調整支架寬度以及connectionstyle引數含義的指導?如果這被記錄在某處,我將不勝感激(即使它帶有 RTFM 型別的注釋)。
uj5u.com熱心網友回復:
我認為你想要的引數是mutation_scale.
我將您的注釋命令更改為此,我認為現在看起來很合理,但需要進行一些手動調整。如果您在多個圖中有一致的模式,您可能可以計算出您想要的角度和長度并將它們用作輸入,但對于您的示例,這似乎作業得相當好。
ax0.annotate(text="Example",
xy=(8.5, -6.5),
xytext=(0, -9),
arrowprops=dict(arrowstyle="-[",
linewidth=1,
mutation_scale=22,
connectionstyle="arc,armA=70, \
angleA=0, \
angleB=-45, \
armB=50, \
rad=0"), \
verticalalignment="bottom",
horizontalalignment="left",
fontsize=8,
bbox=bbox)
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/473880.html
標籤:matplotlib 注释
