pwtools.mpl.Plot

class pwtools.mpl.Plot(fig=None, ax=None, projection='2d', **kwds)[source]

Bases: object

Container for a plot figure with (by default one) axis ax.

You can add more axes with twinx() etc and operate on them.

Examples

# same as Plot(*mpl.fig_ax()), i.e. default is 2d plot >>> pp = mpl.Plot() >>> pp.ax.plot([1,2,3], label=’ax’) >>> pp.ax2 = pp.ax.twinx() >>> pp.ax2.plot([3,2,1], ‘r’, label=’ax2’) >>> # legend on ax (default legaxname=’ax’) with all lines from ax and >>> # ax2 >>> pp.legend([‘ax’, ‘ax2’], loc=’lower left’) >>> pp.fig.savefig(‘lala.png’) >>> pp.fig.savefig(‘lala.pdf’) >>> # or >>> pp.savefig(‘lala’, ext=[‘png’, ‘pdf’])

__init__(fig=None, ax=None, projection='2d', **kwds)[source]
Parameters:
  • fig (Figure + Axis instance (e.g. from fig_ax())) –

  • ax (Figure + Axis instance (e.g. from fig_ax())) –

  • projection (str, optional) – If fig+ax not given, use this to call fig_ax() or fig_ax3d(), else ignored.

  • kwds (keywords passed to fig_ax() or fig_ax3d() if fig=None and) – ax=None

Methods

collect_legends([axnames])

If self has more then one axis object attached, then collect legends from all axes specified in axnames.

legend([axnames, legaxname])

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

savefig(base[, ext])