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='')
| 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 matplotlib_inline.backend_inline 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 docstrings of |
| 69 | `matplotlib_inline.backend_inline.set_matplotlib_formats` and |
| 70 | `matplotlib_inline.backend_inline.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', 'gtk4', 'notebook', 'wx', 'qt', 'nbagg', |
| 92 | 'gtk', 'tk', 'inline'] |
| 93 | """ |
| 94 | args = magic_arguments.parse_argstring(self.matplotlib, line) |
| 95 | if args.list: |
| 96 | from IPython.core.pylabtools import _list_matplotlib_backends_and_gui_loops |
| 97 | |
| 98 | print( |
| 99 | "Available matplotlib backends: %s" |
| 100 | % _list_matplotlib_backends_and_gui_loops() |
| 101 | ) |
| 102 | else: |
| 103 | gui, backend = self.shell.enable_matplotlib(args.gui) |
| 104 | self._show_matplotlib_backend(args.gui, backend) |
nothing calls this directly
no test coverage detected