MCPcopy Create free account
hub / github.com/ipython/ipython / matplotlib

Method matplotlib

IPython/core/magics/pylab.py:47–100  ·  view source on GitHub ↗

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 in the IPython

(self, line='')

Source from the content-addressed store, hash-verified

45 help='Show available matplotlib backends')
46 @magic_gui_arg
47 def matplotlib(self, line=''):
48 """Set up matplotlib to work interactively.
49
50 This function lets you activate matplotlib interactive support
51 at any point during an IPython session. It does not import anything
52 into the interactive namespace.
53
54 If you are using the inline matplotlib backend in the IPython Notebook
55 you can set which figure formats are enabled using the following::
56
57 In [1]: from IPython.display import set_matplotlib_formats
58
59 In [2]: set_matplotlib_formats('pdf', 'svg')
60
61 The default for inline figures sets `bbox_inches` to 'tight'. This can
62 cause discrepancies between the displayed image and the identical
63 image created using `savefig`. This behavior can be disabled using the
64 `%config` magic::
65
66 In [3]: %config InlineBackend.print_figure_kwargs = {'bbox_inches':None}
67
68 In addition, see the docstring of
69 `IPython.display.set_matplotlib_formats` and
70 `IPython.display.set_matplotlib_close` for more information on
71 changing additional behaviors of the inline backend.
72
73 Examples
74 --------
75 To enable the inline backend for usage with the IPython Notebook::
76
77 In [1]: %matplotlib inline
78
79 In this case, where the matplotlib default is TkAgg::
80
81 In [2]: %matplotlib
82 Using matplotlib backend: TkAgg
83
84 But you can explicitly request a different GUI backend::
85
86 In [3]: %matplotlib qt
87
88 You can list the available backends using the -l/--list option::
89
90 In [4]: %matplotlib --list
91 Available matplotlib backends: ['osx', 'qt4', 'qt5', 'gtk3', 'notebook', 'wx', 'qt', 'nbagg',
92 'gtk', 'tk', 'inline']
93 """
94 args = magic_arguments.parse_argstring(self.matplotlib, line)
95 if args.list:
96 backends_list = list(backends.keys())
97 print("Available matplotlib backends: %s" % backends_list)
98 else:
99 gui, backend = self.shell.enable_matplotlib(args.gui.lower() if isinstance(args.gui, str) else args.gui)
100 self._show_matplotlib_backend(args.gui, backend)
101
102 @skip_doctest
103 @line_magic

Callers

nothing calls this directly

Calls 3

parse_argstringMethod · 0.80
enable_matplotlibMethod · 0.80

Tested by

no test coverage detected