I prefer to use Matplotlib's object-oriented API, operating on figures and axes directly, rather than use matplotlib.pyplot
commands.
However I often find it easier to find documentation on how to do something via the pyplot
interface. In these cases it would be really useful to find out what the relevant pyplot
commands are doing in terms of Figure and Axes methods, as it would help me handle whatever specific corner case I was wrestling with when I went looking for documentation.
For instance, plt.xlabel()
is equivalent to ax.set_xlabel()
if ax
is the "current" axes in pyplot's stateful interface. But I can't find anything in the xlabel()
documentation that mentions Axes.set_xlabel()
at all. In this case it's not too hard to look up separately in the Axes documentation, but a mapping would be really nice.
Is there any source of information that would tell me what each particular pyplot
command does in terms of the object-oriented interface?
Use the source, Luke! Many pyplot commans are just very thin wrappers around Axes
or Figure
methods. I usually use IPython.
In [1]: import matplotlib.pyplot as plt
In [2]: plt.xlabel??
Signature: plt.xlabel(s, *args, **kwargs)
Source:
def xlabel(s, *args, **kwargs):
"""
Set the *x* axis label of the current axis.
Default override is::
override = {
'fontsize' : 'small',
'verticalalignment' : 'top',
'horizontalalignment' : 'center'
}
.. seealso::
:func:`~matplotlib.pyplot.text`
For information on how override and the optional args work
"""
return gca().set_xlabel(s, *args, **kwargs)
File: ~\appdata\local\programs\python\python36-32\lib\site-packages\matplotlib\pyplot.py
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