Module: core.pylabtools

Pylab (matplotlib) support utilities.

9 Functions

IPython.core.pylabtools.getfigs(*fig_nums)

Get a list of matplotlib figures by figure numbers.

If no arguments are given, all available figures are returned. If the argument list contains references to invalid figures, a warning is printed but the function continues pasting further figures.

Parameters:

figs (tuple) – A tuple of ints giving the figure numbers of the figures to return.

IPython.core.pylabtools.figsize(sizex, sizey)

Set the default figure size to be [sizex, sizey].

This is just an easy to remember, convenience wrapper that sets:

matplotlib.rcParams['figure.figsize'] = [sizex, sizey]
IPython.core.pylabtools.print_figure(fig, fmt='png', bbox_inches='tight', base64=False, **kwargs)

Print a figure to an image, and return the resulting file data

Returned data will be bytes unless fmt='svg', in which case it will be unicode.

Any keyword args are passed to fig.canvas.print_figure, such as quality or bbox_inches.

If base64 is True, return base64-encoded str instead of raw bytes for binary-encoded image formats

Added in version 7.29: base64 argument

IPython.core.pylabtools.retina_figure(fig, base64=False, **kwargs)

format a figure as a pixel-doubled (retina) PNG

If base64 is True, return base64-encoded str instead of raw bytes for binary-encoded image formats

Added in version 7.29: base64 argument

IPython.core.pylabtools.mpl_runner(safe_execfile)

Factory to return a matplotlib-enabled runner for %run.

Parameters:

safe_execfile (function) – This must be a function with the same interface as the safe_execfile() method of IPython.

Returns:

  • A function suitable for use as the runner argument of the %run magic

  • function.

IPython.core.pylabtools.select_figure_formats(shell, formats, **kwargs)

Select figure formats for the inline backend.

Parameters:
  • shell (InteractiveShell) – The main IPython instance.

  • formats (str or set) – One or a set of figure formats to enable: ‘png’, ‘retina’, ‘jpeg’, ‘svg’, ‘pdf’.

  • **kwargs (any) – Extra keyword arguments to be passed to fig.canvas.print_figure.

IPython.core.pylabtools.find_gui_and_backend(gui=None, gui_select=None)

Given a gui string return the gui and mpl backend.

Parameters:
  • gui (str) – Can be one of (‘tk’,’gtk’,’wx’,’qt’,’qt4’,’inline’,’agg’).

  • gui_select (str) – Can be one of (‘tk’,’gtk’,’wx’,’qt’,’qt4’,’inline’). This is any gui already selected by the shell.

Returns:

  • A tuple of (gui, backend) where backend is one of (‘TkAgg’,’GTKAgg’,

  • ’WXAgg’,’Qt4Agg’,’module (//matplotlib_inline.backend_inline’,’agg’).)

IPython.core.pylabtools.activate_matplotlib(backend)

Activate the given backend and set interactive to True.

IPython.core.pylabtools.import_pylab(user_ns, import_all=True)

Populate the namespace with pylab-related values.

Imports matplotlib, pylab, numpy, and everything from pylab and numpy.

Also imports a few names from IPython (figsize, display, getfigs)