pwtools.mpl.Plot.legend

Plot.legend(axnames=None, legaxname='ax', **kwargs)[source]

Collect legend entries from all axes in axnames and place legend on the axis named with legaxname.

Parameters:
  • axnames (None or list of axes names, optional) – e.g. [‘ax’] or [‘ax’, ‘ax2’]. If None (default) then ax.legend() is called directly (if legaxname=’ax’).

  • legaxname (string, optional) –

    The name of the axis where the legend is placed on. If you use things like twinx(), then you may want to choose top most the axis, i.e. the one in the foreground. For example:

    >>> pp = Plot(...)
    >>> pp.ax.plot(...)
    >>> pp.ax2 = pp.ax.twinx()
    >>> pp.ax2.plot(...)
    >>> pp.legend(axnames=['ax', 'ax2'], legaxname='ax2')
    

Notes

This is not completly transparent. This:

>>> plot = Plot(...)
>>> plot.ax.plot(...)
>>> plot.legend(...)

does only behave as ax.legend() if only kwargs are used. For anything else, use

>>> plot.ax.legend()

directly.