如何控制注释箭头

How to gain control over annotate arrows

我正在尝试使用 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()

我希望括号跨越所有绘制线的宽度(好像在说“这些”线是注释所指的内容),但我不知道如何更改括号宽度。

另一个问题是解释 armAarmB(箭头线目前看起来很难看)。我知道这些是指线段的长度,但我不知道单位是什么(像素?),更不用说如何自动生成它们的长度了。

能否请您指导如何调整括号的宽度以及connectionstyle参数的含义?如果这被记录在某处,我将不胜感激参考(即使它带有 RTFM 类型的注释)。

我想你要的参数是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)