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 display 4
(self, gui=None)
| 3805 | raise NotImplementedError('Implement enable_gui in a subclass') |
| 3806 | |
| 3807 | def enable_matplotlib(self, gui=None): |
| 3808 | """Enable interactive matplotlib and inline figure support. |
| 3809 | |
| 3810 | This takes the following steps: |
| 3811 | |
| 3812 | 1. select the appropriate eventloop and matplotlib backend |
| 3813 | 2. set up matplotlib for interactive use with that backend |
| 3814 | 3. configure formatters for inline figure display |
| 3815 | 4. enable the selected gui eventloop |
| 3816 | |
| 3817 | Parameters |
| 3818 | ---------- |
| 3819 | gui : optional, string |
| 3820 | If given, dictates the choice of matplotlib GUI backend to use |
| 3821 | (should be one of IPython's supported backends, 'qt', 'osx', 'tk', |
| 3822 | 'gtk', 'wx' or 'inline'), otherwise we use the default chosen by |
| 3823 | matplotlib (as dictated by the matplotlib build-time options plus the |
| 3824 | user's matplotlibrc configuration file). Note that not all backends |
| 3825 | make sense in all contexts, for example a terminal ipython can't |
| 3826 | display figures inline. |
| 3827 | """ |
| 3828 | from .pylabtools import _matplotlib_manages_backends |
| 3829 | |
| 3830 | if not _matplotlib_manages_backends() and gui in (None, "auto"): |
| 3831 | # Early import of backend_inline required for its side effect of |
| 3832 | # calling _enable_matplotlib_integration() |
| 3833 | import matplotlib_inline.backend_inline |
| 3834 | |
| 3835 | from IPython.core import pylabtools as pt |
| 3836 | gui, backend = pt.find_gui_and_backend(gui, self.pylab_gui_select) |
| 3837 | |
| 3838 | if gui != None: |
| 3839 | # If we have our first gui selection, store it |
| 3840 | if self.pylab_gui_select is None: |
| 3841 | self.pylab_gui_select = gui |
| 3842 | # Otherwise if they are different |
| 3843 | elif gui != self.pylab_gui_select: |
| 3844 | print('Warning: Cannot change to a different GUI toolkit: %s.' |
| 3845 | ' Using %s instead.' % (gui, self.pylab_gui_select)) |
| 3846 | gui, backend = pt.find_gui_and_backend(self.pylab_gui_select) |
| 3847 | |
| 3848 | pt.activate_matplotlib(backend) |
| 3849 | |
| 3850 | from matplotlib_inline.backend_inline import configure_inline_support |
| 3851 | |
| 3852 | configure_inline_support(self, backend) |
| 3853 | |
| 3854 | # Now we must activate the gui pylab wants to use, and fix %run to take |
| 3855 | # plot updates into account |
| 3856 | self.enable_gui(gui) |
| 3857 | self.magics_manager.registry['ExecutionMagics'].default_runner = \ |
| 3858 | pt.mpl_runner(self.safe_execfile) |
| 3859 | |
| 3860 | return gui, backend |
| 3861 | |
| 3862 | def enable_pylab(self, gui=None, import_all=True): |
| 3863 | """Activate pylab support at runtime. |