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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With