Matplotlib:用垂直箭头和居中文本注释绘图

Fri*_*ant 4 python matplotlib plot-annotations

我想用垂直箭头注释绘图,然后将注释居中于垂直箭头的尖端: 在此输入图像描述

这是我使用的代码:

import matplotlib.pyplot as plt
plt.annotate(
# Label and coordinate
'Help here!', xy=(8, 0.4),xytext=(7.05, 0.6) ,
# Custom arrow
arrowprops=dict(arrowstyle='->',lw=1)
)
Run Code Online (Sandbox Code Playgroud)

xytext 坐标表示文本开始的坐标。如果设置不正确,箭头将不再垂直。现在,为了使箭头垂直,我需要手动找到变量 xytext 的正确 x 坐标(对于此文本,它似乎是 7.05)。但我能找到一种方法来表明我想要的命令吗?

Fri*_*ant 7

ImportanceOfBeingErnest 在评论中给了我回复。以下是与他的响应相关的代码:

import matplotlib.pyplot as plt
plt.annotate(
# Label and coordinate
'Help here!', xy=(8, 0.4),xytext=(8, 0.6) ,
horizontalalignment="center",
# Custom arrow
arrowprops=dict(arrowstyle='->',lw=1)
)
Run Code Online (Sandbox Code Playgroud)