IPython Documentation

Table Of Contents

Previous topic

Module: core.magics.osm

Next topic

Module: core.magics.script

This Page

Warning

This documentation is for an old version of IPython. You can find docs for newer versions here.

Module: core.magics.pylab

Implementation of magic functions for matplotlib/pylab support.

1 Class

class IPython.core.magics.pylab.PylabMagics(shell)

Bases: IPython.core.magic.Magics

Magics related to matplotlib’s pylab support

matplotlib(line='')

%matplotlib [gui]

Set up matplotlib to work interactively.

This function lets you activate matplotlib interactive support at any point during an IPython session. It does not import anything into the interactive namespace.

If you are using the inline matplotlib backend for embedded figures, you can adjust its behavior via the %config magic:

# enable SVG figures, necessary for SVG+XHTML export in the qtconsole
In [1]: %config InlineBackend.figure_format = 'svg'

# change the behavior of closing all figures at the end of each
# execution (cell), or allowing reuse of active figures across
# cells:
In [2]: %config InlineBackend.close_figures = False

Examples

In this case, where the MPL default is TkAgg:

In [2]: %matplotlib
Using matplotlib backend: TkAgg

But you can explicitly request a different backend:

In [3]: %matplotlib qt
positional arguments:
gui Name of the matplotlib backend to use (‘gtk’, ‘inline’, ‘osx’, ‘qt’,
‘qt4’, ‘tk’, ‘wx’). If given, the corresponding matplotlib backend is used, otherwise it will be matplotlib’s default (which you can set in your matplotlib config file).
pylab(line='')

%pylab [–no-import-all] [gui]

Load numpy and matplotlib to work interactively.

This function lets you activate pylab (matplotlib, numpy and interactive support) at any point during an IPython session.

%pylab makes the following imports:

import numpy
import matplotlib
from matplotlib import pylab, mlab, pyplot
np = numpy
plt = pyplot

from IPython.display import display
from IPython.core.pylabtools import figsize, getfigs

from pylab import *
from numpy import *

If you pass –no-import-all, the last two * imports will be excluded.

See the %matplotlib magic for more details about activating matplotlib without affecting the interactive namespace.

positional arguments:
gui Name of the matplotlib backend to use (‘gtk’, ‘inline’,
‘osx’, ‘qt’, ‘qt4’, ‘tk’, ‘wx’). If given, the corresponding matplotlib backend is used, otherwise it will be matplotlib’s default (which you can set in your matplotlib config file).
optional arguments:
--no-import-all
 Prevent IPython from performing import * into the interactive namespace. You can govern the default behavior of this flag with the InteractiveShellApp.pylab_import_all configurable.