我是 matplotlib 的新手,我试图将文本设置为图中的一个点,但出现错误:
回溯(最近一次调用最后一次):文件“main.py”,第 239 行,在 main() 文件“main.py”,第 232 行,在主 p.show_graphic_ortg_drtg() 文件“/home/josecarlos/Workspace/python/ process/process.py",第 363 行,在 show_graphic_ortg_drtg Axes.Axes.annotate(xy=(df[0:1]["ortg"], df[0:1]["drtg"]), s="Hola ") TypeError: annotate() 缺少 1 个必需的位置参数:'self'
我的代码是:
import matplotlib.axes as Axes
Axes.Axes.annotate(xy=(df[0:1]["ortg"], df[0:1]["drtg"]), s="Message")
Run Code Online (Sandbox Code Playgroud)
df 是之前生成的 Pandas 的 DataFrame。
我究竟做错了什么?我正在遵循一些教程和文档,但没有发现错误。
您不能直接从类中调用非静态方法。您需要首先实例化坐标区对象。
获取 Axes 实例的方法有很多。一个简单而紧凑的方法是:
fig, ax = plt.subplots()
# this function returns an instance of the Figure class
# and an instance of the Axes class.
ax.annotate(...)
# call annotate() from the Axes instance
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
21384 次 |
最近记录: |