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)。但我能找到一种方法来表明我想要的命令吗?
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)
| 归档时间: |
|
| 查看次数: |
10142 次 |
| 最近记录: |