Matplotlib plt.xlabel() vs ax.set_xlabel()

Viewed 3908

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()?

1 Answers
Related