Enable interactive matplotlib and inline figure support. This takes the following steps: 1. select the appropriate eventloop and matplotlib backend 2. set up matplotlib for interactive use with that backend 3. configure formatters for inline figure d
(self, gui=None)
| 3469 | raise NotImplementedError('Implement enable_gui in a subclass') |
| 3470 | |
| 3471 | def enable_matplotlib(self, gui=None): |
| 3472 | """Enable interactive matplotlib and inline figure support. |
| 3473 | |
| 3474 | This takes the following steps: |
| 3475 | |
| 3476 | 1. select the appropriate eventloop and matplotlib backend |
| 3477 | 2. set up matplotlib for interactive use with that backend |
| 3478 | 3. configure formatters for inline figure display |
| 3479 | 4. enable the selected gui eventloop |
| 3480 | |
| 3481 | Parameters |
| 3482 | ---------- |
| 3483 | gui : optional, string |
| 3484 | If given, dictates the choice of matplotlib GUI backend to use |
| 3485 | (should be one of IPython's supported backends, 'qt', 'osx', 'tk', |
| 3486 | 'gtk', 'wx' or 'inline'), otherwise we use the default chosen by |
| 3487 | matplotlib (as dictated by the matplotlib build-time options plus the |
| 3488 | user's matplotlibrc configuration file). Note that not all backends |
| 3489 | make sense in all contexts, for example a terminal ipython can't |
| 3490 | display figures inline. |
| 3491 | """ |
| 3492 | from IPython.core import pylabtools as pt |
| 3493 | gui, backend = pt.find_gui_and_backend(gui, self.pylab_gui_select) |
| 3494 | |
| 3495 | if gui != 'inline': |
| 3496 | # If we have our first gui selection, store it |
| 3497 | if self.pylab_gui_select is None: |
| 3498 | self.pylab_gui_select = gui |
| 3499 | # Otherwise if they are different |
| 3500 | elif gui != self.pylab_gui_select: |
| 3501 | print('Warning: Cannot change to a different GUI toolkit: %s.' |
| 3502 | ' Using %s instead.' % (gui, self.pylab_gui_select)) |
| 3503 | gui, backend = pt.find_gui_and_backend(self.pylab_gui_select) |
| 3504 | |
| 3505 | pt.activate_matplotlib(backend) |
| 3506 | pt.configure_inline_support(self, backend) |
| 3507 | |
| 3508 | # Now we must activate the gui pylab wants to use, and fix %run to take |
| 3509 | # plot updates into account |
| 3510 | self.enable_gui(gui) |
| 3511 | self.magics_manager.registry['ExecutionMagics'].default_runner = \ |
| 3512 | pt.mpl_runner(self.safe_execfile) |
| 3513 | |
| 3514 | return gui, backend |
| 3515 | |
| 3516 | def enable_pylab(self, gui=None, import_all=True, welcome_message=False): |
| 3517 | """Activate pylab support at runtime. |