首页 > 解决方案 > xycoords 由数据(x 位置)和图形/轴(y 位置)给出的注释?

问题描述

是否可以进行注释,其中xycoords数据(x 位置)和图形(y 位置)给出?

标签: matplotlib

解决方案


是的。这是确认我的答案的演示代码。

import matplotlib.pyplot as plt
import matplotlib.transforms as transforms

fig, ax = plt.subplots()

# the x coords of this transformation are data, and the
#   y coord axes
# Note the use of different .transXXXX options
trans = transforms.blended_transform_factory(ax.transData, \
                                             ax.transAxes)
ax.plot((12,43,56),(632,0,543))

# annotate() takes `xycoords=trans`
# head location
xh = 30   #Data coordinate
yh = 0.25 #Axes coordinate
# tail location (also text)
xt = 40   #Data coordinate
yt = 0.5  #Axes coordinate
ax.annotate("v-centered", (xh, yh), xytext=(xt, yt), \
            xycoords=trans, arrowprops={'arrowstyle': '->'})

plt.show()

在此处输入图像描述


推荐阅读