I am using some code that uses the singleton-version of matplotlib in Python, i.e. it has calls like
plt.figure()
...
plt.xlabel("abc")
I am trying to convert it to the functional/memory-less version:
fig,ax = plt.subplots()
...
ax.set_xlabel("abc")
A couple questions:
Is there an option to set the xlabel of an axes directly? Something
like ax.xlabel = "xlabel string"?
From the documentation, it seems like this is not possible. (not even a private attribute we can set)
Or is it always required to go through the setter? This has always confused me and struck me as non-Pythonic.
Why did the API change going from plt.xlabel() to ax.set_xlabel()?
Matplotlib had the pyplot interface, and then later developed the object-oriented interface, as described in the documentation (https://matplotlib.org/3.2.1/tutorials/introductory/lifecycle.html).
The latter is now preferred, so use fig, ax = plt.subplots and then use the setter method on ax.
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