Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there documentation mapping matplotlib's stateful pyplot API to the object-oriented equivalents?

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?

like image 200
user2428107 Avatar asked Jan 03 '23 17:01

user2428107


1 Answers

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
like image 119
Stop harming Monica Avatar answered Jan 13 '23 22:01

Stop harming Monica