matplotlib - xycoords 由数据(x 位置)和图形/轴(y 位置)给出的注释?
问题描述
是否可以进行注释,其中xycoords由数据(x 位置)和图形或轴(y 位置)给出?
解决方案
是的。这是确认我的答案的演示代码。
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()
推荐阅读
- facebook-graph-api - 获取托管页面列表
- javascript - 对 slack 的 JSON 发布请求返回 invalid_auth
- node.js - 发布节点应用程序
- angular - 仅在用户首次登录时将其重定向到页面
- mysql - 空文本是否占用数据库中的空间
- python - 不可散列的类型:从 Python 中的列表值中删除字符时出现“切片”错误?
- data-visualization - 百度下载ECharts中的可视化截图和数据
- swift - swift中Range的index(of:Int)方法返回不正确的值
- python - 使用正则表达式解析文本以提取有效段落
- mdx - MDX 中的多个集合使用 WITH 函数