Esempio n. 1
0
 def init_gui_pylab(self):
     """Enable GUI event loop integration, taking pylab into account."""
     if self.gui or self.pylab:
         shell = self.shell
         try:
             if self.pylab:
                 gui, backend = pylabtools.find_gui_and_backend(self.pylab)
                 self.log.info("Enabling GUI event loop integration, " "toolkit=%s, pylab=%s" % (gui, self.pylab))
                 shell.enable_pylab(gui, import_all=self.pylab_import_all)
             else:
                 self.log.info("Enabling GUI event loop integration, " "toolkit=%s" % self.gui)
                 shell.enable_gui(self.gui)
         except Exception:
             self.log.warn("GUI event loop or pylab initialization failed")
             self.shell.showtraceback()
Esempio n. 2
0
 def init_gui_pylab(self):
     """Enable GUI event loop integration, taking pylab into account."""
     if self.gui or self.pylab:
         shell = self.shell
         try:
             if self.pylab:
                 gui, backend = pylabtools.find_gui_and_backend(self.pylab)
                 self.log.info("Enabling GUI event loop integration, "
                               "toolkit=%s, pylab=%s" % (gui, self.pylab))
                 shell.enable_pylab(gui, import_all=self.pylab_import_all)
             else:
                 self.log.info("Enabling GUI event loop integration, "
                               "toolkit=%s" % self.gui)
                 shell.enable_gui(self.gui)
         except Exception:
             self.log.warn("GUI event loop or pylab initialization failed")
             self.shell.showtraceback()
Esempio n. 3
0
    def init_kernel(self):

        kernel = Kernel(
            config=self.config,
            session=self.session,
            shell_socket=self.shell_socket,
            iopub_socket=self.iopub_socket,
            stdin_socket=self.stdin_socket,
            log=self.log,
            profile_dir=self.profile_dir,
        )
        self.kernel = kernel
        kernel.record_ports(self.ports)
        shell = kernel.shell
        if self.pylab:
            try:
                gui, backend = pylabtools.find_gui_and_backend(self.pylab)
                shell.enable_pylab(gui, import_all=self.pylab_import_all)
            except Exception:
                self.log.error("Pylab initialization failed", exc_info=True)
                # print exception straight to stdout, because normally
                # _showtraceback associates the reply with an execution,
                # which means frontends will never draw it, as this exception
                # is not associated with any execute request.

                # replace pyerr-sending traceback with stdout
                _showtraceback = shell._showtraceback

                def print_tb(etype, evalue, stb):
                    print(
                        "Error initializing pylab, pylab mode will not "
                        "be active",
                        file=io.stderr)
                    print(shell.InteractiveTB.stb2text(stb), file=io.stdout)

                shell._showtraceback = print_tb

                # send the traceback over stdout
                shell.showtraceback(tb_offset=0)

                # restore proper _showtraceback method
                shell._showtraceback = _showtraceback
Esempio n. 4
0
    def init_kernel(self):

        shell_stream = ZMQStream(self.shell_socket)

        kernel = Kernel(
            config=self.config,
            session=self.session,
            shell_streams=[shell_stream],
            iopub_socket=self.iopub_socket,
            stdin_socket=self.stdin_socket,
            log=self.log,
            profile_dir=self.profile_dir,
        )
        self.kernel = kernel
        kernel.record_ports(self.ports)
        shell = kernel.shell
        if self.pylab:
            try:
                gui, backend = pylabtools.find_gui_and_backend(self.pylab)
                shell.enable_pylab(gui, import_all=self.pylab_import_all)
            except Exception:
                self.log.error("Pylab initialization failed", exc_info=True)
                # print exception straight to stdout, because normally
                # _showtraceback associates the reply with an execution,
                # which means frontends will never draw it, as this exception
                # is not associated with any execute request.

                # replace pyerr-sending traceback with stdout
                _showtraceback = shell._showtraceback

                def print_tb(etype, evalue, stb):
                    print("Error initializing pylab, pylab mode will not " "be active", file=io.stderr)
                    print(shell.InteractiveTB.stb2text(stb), file=io.stdout)

                shell._showtraceback = print_tb

                # send the traceback over stdout
                shell.showtraceback(tb_offset=0)

                # restore proper _showtraceback method
                shell._showtraceback = _showtraceback
Esempio n. 5
0
 def init_gui_pylab(self):
     """Enable GUI event loop integration, taking pylab into account."""
     if self.gui or self.pylab:
         shell = self.shell
         try:
             if self.pylab:
                 gui, backend = pylabtools.find_gui_and_backend(self.pylab)
                 self.log.info("Enabling GUI event loop integration, "
                           "toolkit=%s, pylab=%s" % (gui, self.pylab))
                 shell.enable_pylab(gui, import_all=self.pylab_import_all, welcome_message=True)
             else:
                 self.log.info("Enabling GUI event loop integration, "
                               "toolkit=%s" % self.gui)
                 shell.enable_gui(self.gui)
         except ImportError:
             self.log.warn("pylab mode doesn't work as matplotlib could not be found." + \
                           "\nIs it installed on the system?")
             self.shell.showtraceback()
         except Exception:
             self.log.warn("GUI event loop or pylab initialization failed")
             self.shell.showtraceback()
Esempio n. 6
0
 def init_gui_pylab(self):
     """Enable GUI event loop integration, taking pylab into account."""
     if self.gui or self.pylab:
         shell = self.shell
         try:
             if self.pylab:
                 gui, backend = pylabtools.find_gui_and_backend(self.pylab)
                 self.log.info("Enabling GUI event loop integration, "
                               "toolkit=%s, pylab=%s" % (gui, self.pylab))
                 shell.enable_pylab(gui,
                                    import_all=self.pylab_import_all,
                                    welcome_message=True)
             else:
                 self.log.info("Enabling GUI event loop integration, "
                               "toolkit=%s" % self.gui)
                 shell.enable_gui(self.gui)
         except ImportError:
             self.log.warn("pylab mode doesn't work as matplotlib could not be found." + \
                           "\nIs it installed on the system?")
             self.shell.showtraceback()
         except Exception:
             self.log.warn("GUI event loop or pylab initialization failed")
             self.shell.showtraceback()
Esempio n. 7
0
    return hasattr(o, k)


def get_convis_attribute(o, k, default=None):
    return getattr(o, k, default)


plotting_possible = False
plotting_exceptions = []
do_3d_plot = True
try:
    import matplotlib
    from matplotlib import cm
    import matplotlib.pylab as plt
    from IPython.core import pylabtools as pt
    gui, backend = pt.find_gui_and_backend('inline', 'inline')
    from IPython.core.pylabtools import activate_matplotlib
    activate_matplotlib(backend)
    plotting_possible = True
except Exception as e:
    plotting_exceptions.append(e)
    pass

doc_urls = [
    ('convis.filters.retina',
     'https://jahuth.github.io/convis/docs_retina.html#'),
    ('convis.filters.spiking',
     'https://jahuth.github.io/convis/filters.html#'),
    ('convis.filters', 'https://jahuth.github.io/convis/docs_filters.html#'),
    ('convis.models', 'https://jahuth.github.io/convis/docs_models.html#'),
    ('convis.retina', 'https://jahuth.github.io/convis/docs_retina.html#'),
Esempio n. 8
0
    186     def magic_deco(arg):
--> 187         call = lambda f, *a, **k: f(*a, **k)
    188
    189         if callable(arg):

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/IPython/core/magics/pylab.py in matplotlib(self, line)
     97             print("Available matplotlib backends: %s" % backends_list)
     98         else:
---> 99             gui, backend = self.shell.enable_matplotlib(args.gui)
    100             self._show_matplotlib_backend(args.gui, backend)
    101

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/IPython/core/interactiveshell.py in enable_matplotlib(self, gui)
   3037
   3038         from IPython.core import pylabtools as pt
-> 3039         gui, backend = pt.find_gui_and_backend(gui, self.pylab_gui_select)
   3040
   3041         if gui != 'inline':

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/IPython/core/pylabtools.py in find_gui_and_backend(gui, gui_select)
    275     if gui and gui != 'auto':
    276         # select backend based on requested gui
--> 277         backend = backends[gui]
    278         if gui == 'agg':
    279             gui = None

KeyError: 'online'

In [16]: import matplotlib.pyplot as plt

In [17]: plt.plot(np.random.randn(50).cumsum())