Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib: annotate() missing 1 required positional argument: 'self'

I'm newbie in matplotlib and I'm trying to set a text to a point in a graph but I've got the error:

Traceback (most recent call last): File "main.py", line 239, in main() File "main.py", line 232, in main p.show_graphic_ortg_drtg() File "/home/josecarlos/Workspace/python/process/process.py", line 363, in show_graphic_ortg_drtg Axes.Axes.annotate(xy=(df[0:1]["ortg"], df[0:1]["drtg"]), s="Hola") TypeError: annotate() missing 1 required positional argument: 'self'

My code is:

import matplotlib.axes as Axes

Axes.Axes.annotate(xy=(df[0:1]["ortg"], df[0:1]["drtg"]), s="Message")

df is a DataFrame from Pandas previously generated.

What am I doing wrong? I'm following some tutorials and documentation and I don't find the mistake.

like image 684
José Carlos Avatar asked Jan 18 '26 09:01

José Carlos


1 Answers

You cannot call a non static method directly from the class. You need to instanciate the axes object first.

There are many ways to get an Axes instance. A simple and compact way is:

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
like image 81
Diziet Asahi Avatar answered Jan 19 '26 21:01

Diziet Asahi