예제 #1
0
    def __call__(self, *args, **params):
        super(notebook_extension, self).__call__(*args, **params)
        # Abort if IPython not found
        try:
            ip = params.pop('ip', None) or get_ipython()  # noqa (get_ipython)
        except:
            return

        # Notebook archive relies on display hooks being set to work.
        try:
            if version_info[0] >= 4:
                import nbformat  # noqa (ensures availability)
            else:
                from IPython import nbformat  # noqa (ensures availability)
            from .archive import notebook_archive
            holoviews.archive = notebook_archive
        except ImportError:
            pass

        # Not quite right, should be set when switching backends
        if 'matplotlib' in Store.renderers and not notebook_extension._loaded:
            svg_exporter = Store.renderers['matplotlib'].instance(holomap=None,
                                                                  fig='svg')
            holoviews.archive.exporters = [svg_exporter
                                           ] + holoviews.archive.exporters

        p = param.ParamOverrides(self, params)
        resources = self._get_resources(args, params)

        Store.display_formats = p.display_formats
        if 'html' not in p.display_formats and len(p.display_formats) > 1:
            msg = ('Output magic unable to control displayed format '
                   'as IPython notebook uses fixed precedence '
                   'between %r' % p.display_formats)
            display(HTML('<b>Warning</b>: %s' % msg))

        if notebook_extension._loaded == False:
            param_ext.load_ipython_extension(ip, verbose=False)
            load_magics(ip)
            Store.output_settings.initialize(list(Store.renderers.keys()))
            set_display_hooks(ip)
            notebook_extension._loaded = True

        css = ''
        if p.width is not None:
            css += '<style>div.container { width: %s%% }</style>' % p.width
        if p.css:
            css += '<style>%s</style>' % p.css
        if css:
            display(HTML(css))

        resources = list(resources)
        if len(resources) == 0: return

        Renderer.load_nb()
        for r in [r for r in resources if r != 'holoviews']:
            Store.renderers[r].load_nb(inline=p.inline)

        # Create a message for the logo (if shown)
        self.load_hvjs(logo=p.logo, JS=('holoviews' in resources), message='')
예제 #2
0
파일: __init__.py 프로젝트: pausz/holoviews
def load_ipython_extension(ip):

    global _loaded
    if not _loaded:
        _loaded = True
        param_ext.load_ipython_extension(ip, verbose=False)
        load_magics(ip)
        OutputMagic.register_supported_formats(OutputMagic.optional_formats)
        set_display_hooks(ip)
예제 #3
0
파일: __init__.py 프로젝트: pausz/holoviews
def load_ipython_extension(ip):

    global _loaded
    if not _loaded:
        _loaded = True
        param_ext.load_ipython_extension(ip, verbose=False)
        load_magics(ip)
        OutputMagic.register_supported_formats(OutputMagic.optional_formats)
        set_display_hooks(ip)
예제 #4
0
def load_ipython_extension(ip):

    global _loaded
    if not _loaded:
        _loaded = True
        param_ext.load_ipython_extension(ip, verbose=False)
        load_magics(ip)
        OutputMagic.initialize()
        set_display_hooks(ip)
        load_notebook()
예제 #5
0
def load_ipython_extension(ip):

    global _loaded
    if not _loaded:
        _loaded = True
        param_ext.load_ipython_extension(ip, verbose=False)
        load_magics(ip)
        if DEFAULT_RENDER_CLASS is not None:
            valid_formats = DEFAULT_RENDER_CLASS.supported_holomap_formats(OutputMagic.optional_formats)
            OutputMagic.register_supported_formats(valid_formats)
        set_display_hooks(ip)
예제 #6
0
def load_ipython_extension(ip, verbose=True):

    if verbose: print(message)

    global _loaded
    if not _loaded:
        _loaded = True

        param_ext.load_ipython_extension(ip, verbose=False)

        load_magics(ip)
        valid_formats = supported_formats(ViewMagic.optional_formats)
        ViewMagic.register_supported_formats(valid_formats)
        set_display_hooks(ip)
        update_matplotlib_rc()
        set_style('default')
예제 #7
0
    def __call__(self, *args, **params):
        resources = self._get_resources(args, params)
        ip = params.pop('ip', None)
        p = param.ParamOverrides(self, params)
        Store.display_formats = p.display_formats

        if 'html' not in p.display_formats and len(p.display_formats) > 1:
            msg = ('Output magic unable to control displayed format '
                   'as IPython notebook uses fixed precedence '
                   'between %r' % p.display_formats)
            display(HTML('<b>Warning</b>: %s' % msg))

        if notebook_extension._loaded == False:
            ip = get_ipython() if ip is None else ip  # noqa (get_ipython)
            param_ext.load_ipython_extension(ip, verbose=False)
            load_magics(ip)
            OutputMagic.initialize()
            set_display_hooks(ip)
            notebook_extension._loaded = True

        css = ''
        if p.width is not None:
            css += '<style>div.container { width: %s%% }</style>' % p.width
        if p.css:
            css += '<style>%s</style>' % p.css
        if css:
            display(HTML(css))

        resources = list(resources)
        if len(resources) == 0: return

        # Create a message for the logo (if shown)
        js_names = {'holoviews': 'HoloViewsJS'}  # resource : displayed name
        loaded = ', '.join(js_names[r] if r in js_names else r.capitalize() +
                           'JS' for r in resources)

        load_hvjs(logo=p.logo,
                  JS=('holoviews' in resources),
                  message='%s successfully loaded in this cell.' % loaded)
        for r in [r for r in resources if r != 'holoviews']:
            Store.renderers[r].load_nb(inline=p.inline)

        if resources[-1] != 'holoviews':
            get_ipython().magic(u"output backend=%r" %
                                resources[-1])  # noqa (get_ipython))
예제 #8
0
    def __call__(self, *args, **params):
        resources = self._get_resources(args, params)
        ip = params.pop("ip", None)
        p = param.ParamOverrides(self, params)
        Store.display_formats = p.display_formats

        if "html" not in p.display_formats and len(p.display_formats) > 1:
            msg = (
                "Output magic unable to control displayed format "
                "as IPython notebook uses fixed precedence "
                "between %r" % p.display_formats
            )
            display(HTML("<b>Warning</b>: %s" % msg))

        if notebook_extension._loaded == False:
            ip = get_ipython() if ip is None else ip  # noqa (get_ipython)
            param_ext.load_ipython_extension(ip, verbose=False)
            load_magics(ip)
            OutputMagic.initialize()
            set_display_hooks(ip)
            notebook_extension._loaded = True

        css = ""
        if p.width is not None:
            css += "<style>div.container { width: %s%% }</style>" % p.width
        if p.css:
            css += "<style>%s</style>" % p.css
        if css:
            display(HTML(css))

        resources = list(resources)
        if len(resources) == 0:
            return

        # Create a message for the logo (if shown)
        js_names = {"holoviews": "HoloViewsJS"}  # resource : displayed name
        loaded = ", ".join(js_names[r] if r in js_names else r.capitalize() + "JS" for r in resources)

        load_hvjs(logo=p.logo, JS=("holoviews" in resources), message="%s successfully loaded in this cell." % loaded)
        for r in [r for r in resources if r != "holoviews"]:
            Store.renderers[r].load_nb()

        if resources[-1] != "holoviews":
            get_ipython().magic(u"output backend=%r" % resources[-1])  # noqa (get_ipython))
예제 #9
0
파일: ipython.py 프로젝트: ceball/imagen
def load_ipython_extension(ip, verbose=True):

    if verbose: print message

    global _loaded
    if not _loaded:
        _loaded = True

        param_ext.load_ipython_extension(ip)

        ip.register_magics(ViewMagic)
        ip.register_magics(OptsMagic)
        ip.register_magics(ChannelMagic)


        # Configuring tab completion
        ip.set_hook('complete_command', ChannelMagic.option_completer, str_key = '%channels')
        ip.set_hook('complete_command', ChannelMagic.option_completer, str_key = '%%channels')

        ip.set_hook('complete_command', ViewMagic.option_completer, str_key = '%view')
        ip.set_hook('complete_command', ViewMagic.option_completer, str_key = '%%view')

        ip.set_hook('complete_command', OptsMagic.option_completer, str_key = '%%opts')
        ip.set_hook('complete_command', OptsMagic.option_completer, str_key = '%opts')


        html_formatter = ip.display_formatter.formatters['text/html']
        html_formatter.for_type_by_name('matplotlib.animation', 'FuncAnimation', animation_display)

        html_formatter.for_type(View, view_display)
        html_formatter.for_type(Stack, stack_display)
        html_formatter.for_type(Layout, layout_display)
        html_formatter.for_type(GridLayout, layout_display)
        html_formatter.for_type(CoordinateGrid, projection_display)

        update_matplotlib_rc()
예제 #10
0
    def __call__(self, *args, **params):
        imports = [(name, b) for name, b in self._backends.items()
                   if name in args or params.get(name, False)]
        if not imports or 'matplotlib' not in Store.renderers:
            imports = imports + [('matplotlib', 'mpl')]

        args = list(args)
        for backend, imp in imports:
            try:
                __import__('holoviews.plotting.%s' % imp)
            except ImportError:
                if backend in args:
                    args.pop(args.index(backend))
                if backend in params:
                    params.pop(backend)
                self.warning("HoloViews %s backend could not be imported, "
                             "ensure %s is installed." % (backend, backend))
            finally:
                if backend == 'matplotlib' and not notebook_extension._loaded:
                    svg_exporter = Store.renderers['matplotlib'].instance(
                        holomap=None, fig='svg')
                    holoviews.archive.exporters = [svg_exporter] +\
                                                  holoviews.archive.exporters
                OutputMagic.allowed['backend'] = list_backends()
                OutputMagic.allowed['fig'] = list_formats('fig', backend)
                OutputMagic.allowed['holomap'] = list_formats(
                    'holomap', backend)
        resources = self._get_resources(args, params)

        ip = params.pop('ip', None)
        p = param.ParamOverrides(self, params)
        Store.display_formats = p.display_formats

        if 'html' not in p.display_formats and len(p.display_formats) > 1:
            msg = ('Output magic unable to control displayed format '
                   'as IPython notebook uses fixed precedence '
                   'between %r' % p.display_formats)
            display(HTML('<b>Warning</b>: %s' % msg))

        if notebook_extension._loaded == False:
            ip = get_ipython() if ip is None else ip  # noqa (get_ipython)
            param_ext.load_ipython_extension(ip, verbose=False)
            load_magics(ip)
            OutputMagic.initialize(list(self._backends.keys()))
            set_display_hooks(ip)
            notebook_extension._loaded = True

        css = ''
        if p.width is not None:
            css += '<style>div.container { width: %s%% }</style>' % p.width
        if p.css:
            css += '<style>%s</style>' % p.css
        if css:
            display(HTML(css))

        resources = list(resources)
        if len(resources) == 0: return

        # Create a message for the logo (if shown)
        js_names = {'holoviews': 'HoloViewsJS'}  # resource : displayed name
        loaded = ', '.join(js_names[r] if r in js_names else r.capitalize() +
                           'JS' for r in resources)

        load_hvjs(logo=p.logo,
                  JS=('holoviews' in resources),
                  message='%s successfully loaded in this cell.' % loaded)
        for r in [r for r in resources if r != 'holoviews']:
            Store.renderers[r].load_nb(inline=p.inline)

        if resources[-1] != 'holoviews':
            get_ipython().magic(u"output backend=%r" %
                                resources[-1])  # noqa (get_ipython))
예제 #11
0
    def __call__(self, *args, **params):
        super(notebook_extension, self).__call__(*args, **params)
        # Abort if IPython not found
        try:
            ip = params.pop('ip', None) or get_ipython()  # noqa (get_ipython)
        except:
            return

        # Notebook archive relies on display hooks being set to work.
        try:
            if version_info[0] >= 4:
                import nbformat  # noqa (ensures availability)
            else:
                from IPython import nbformat  # noqa (ensures availability)
            from .archive import notebook_archive
            holoviews.archive = notebook_archive
        except ImportError:
            pass

        # Not quite right, should be set when switching backends
        if 'matplotlib' in Store.renderers and not notebook_extension._loaded:
            svg_exporter = Store.renderers['matplotlib'].instance(holomap=None,
                                                                  fig='svg')
            holoviews.archive.exporters = [svg_exporter
                                           ] + holoviews.archive.exporters

        p = param.ParamOverrides(
            self, {k: v
                   for k, v in params.items() if k != 'config'})
        if p.case_sensitive_completion:
            from IPython.core import completer
            completer.completions_sorting_key = self.completions_sorting_key

        resources = self._get_resources(args, params)

        Store.display_formats = p.display_formats
        if 'html' not in p.display_formats and len(p.display_formats) > 1:
            msg = ('Output magic unable to control displayed format '
                   'as IPython notebook uses fixed precedence '
                   'between %r' % p.display_formats)
            display(HTML('<b>Warning</b>: %s' % msg))

        loaded = notebook_extension._loaded
        if loaded == False:
            param_ext.load_ipython_extension(ip, verbose=False)
            load_magics(ip)
            Store.output_settings.initialize(list(Store.renderers.keys()))
            Store.set_display_hook('html+js', LabelledData, pprint_display)
            Store.set_display_hook('png', LabelledData, png_display)
            Store.set_display_hook('svg', LabelledData, svg_display)
            notebook_extension._loaded = True

        css = ''
        if p.width is not None:
            css += '<style>div.container { width: %s%% }</style>' % p.width
        if p.css:
            css += '<style>%s</style>' % p.css
        if css:
            display(HTML(css))

        resources = list(resources)
        if len(resources) == 0: return

        Renderer.load_nb()
        for r in [r for r in resources if r != 'holoviews']:
            Store.renderers[r].load_nb(inline=p.inline)

        if hasattr(ip, 'kernel') and not loaded:
            Renderer.comm_manager.get_client_comm(
                notebook_extension._process_comm_msg, "hv-extension-comm")

        # Create a message for the logo (if shown)
        self.load_hvjs(
            logo=p.logo,
            bokeh_logo=p.logo and ('bokeh' in resources),
            mpl_logo=p.logo
            and (('matplotlib' in resources) or resources == ['holoviews']),
            plotly_logo=p.logo and ('plotly' in resources),
            JS=('holoviews' in resources))
예제 #12
0
    def __call__(self, *args, **params):
        super(notebook_extension, self).__call__(*args, **params)
        # Abort if IPython not found
        try:
            ip = params.pop('ip', None) or get_ipython() # noqa (get_ipython)
        except:
            return

        # Notebook archive relies on display hooks being set to work.
        try:
            if version_info[0] >= 4:
                import nbformat # noqa (ensures availability)
            else:
                from IPython import nbformat # noqa (ensures availability)
            from .archive import notebook_archive
            holoviews.archive = notebook_archive
        except ImportError:
            pass

        # Not quite right, should be set when switching backends
        if 'matplotlib' in Store.renderers and not notebook_extension._loaded:
            svg_exporter = Store.renderers['matplotlib'].instance(holomap=None,fig='svg')
            holoviews.archive.exporters = [svg_exporter] + holoviews.archive.exporters

        p = param.ParamOverrides(self, {k:v for k,v in params.items() if k!='config'})
        if p.case_sensitive_completion:
            from IPython.core import completer
            completer.completions_sorting_key = self.completions_sorting_key

        resources = self._get_resources(args, params)

        Store.display_formats = p.display_formats
        if 'html' not in p.display_formats and len(p.display_formats) > 1:
            msg = ('Output magic unable to control displayed format '
                   'as IPython notebook uses fixed precedence '
                   'between %r' % p.display_formats)
            display(HTML('<b>Warning</b>: %s' % msg))

        if notebook_extension._loaded == False:
            param_ext.load_ipython_extension(ip, verbose=False)
            load_magics(ip)
            Store.output_settings.initialize(list(Store.renderers.keys()))
            set_display_hooks(ip)
            notebook_extension._loaded = True

        css = ''
        if p.width is not None:
            css += '<style>div.container { width: %s%% }</style>' % p.width
        if p.css:
            css += '<style>%s</style>' % p.css
        if css:
            display(HTML(css))

        resources = list(resources)
        if len(resources) == 0: return

        Renderer.load_nb()
        for r in [r for r in resources if r != 'holoviews']:
            Store.renderers[r].load_nb(inline=p.inline)

        # Create a message for the logo (if shown)
        self.load_hvjs(logo=p.logo,
                       bokeh_logo=  p.logo and ('bokeh' in resources),
                       mpl_logo=    p.logo and (('matplotlib' in resources)
                                                or resources==['holoviews']),
                       plotly_logo= p.logo and ('plotly' in resources),
                       JS=('holoviews' in resources))
예제 #13
0
    def __call__(self, *args, **params):
        imports = [(name, b) for name, b in self._backends.items()
                   if name in args or params.get(name, False)]
        if not imports:
            imports.append(('matplotlib', 'mpl'))
        for backend, imp in imports:
            try:
                __import__('holoviews.plotting.%s' % imp)
            except ImportError:
                self.warning("HoloViews %s backend could not be imported, "
                             "ensure %s is installed." % (backend, backend))
            finally:
                if backend == 'matplotlib' and not notebook_extension._loaded:
                    svg_exporter = Store.renderers['matplotlib'].instance(holomap=None,
                                                                          fig='svg')
                    holoviews.archive.exporters = [svg_exporter] +\
                                                  holoviews.archive.exporters
                OutputMagic.allowed['backend'] = list_backends()
                OutputMagic.allowed['fig'] = list_formats('fig', backend)
                OutputMagic.allowed['holomap'] = list_formats('holomap', backend)
        resources = self._get_resources(args, params)

        ip = params.pop('ip', None)
        p = param.ParamOverrides(self, params)
        Store.display_formats = p.display_formats

        if 'html' not in p.display_formats and len(p.display_formats) > 1:
            msg = ('Output magic unable to control displayed format '
                   'as IPython notebook uses fixed precedence '
                   'between %r' % p.display_formats)
            display(HTML('<b>Warning</b>: %s' % msg))

        if notebook_extension._loaded == False:
            ip = get_ipython() if ip is None else ip # noqa (get_ipython)
            param_ext.load_ipython_extension(ip, verbose=False)
            load_magics(ip)
            OutputMagic.initialize()
            set_display_hooks(ip)
            notebook_extension._loaded = True

        css = ''
        if p.width is not None:
            css += '<style>div.container { width: %s%% }</style>' % p.width
        if p.css:
            css += '<style>%s</style>' % p.css
        if css:
            display(HTML(css))

        resources = list(resources)
        if len(resources) == 0: return

        # Create a message for the logo (if shown)
        js_names = {'holoviews':'HoloViewsJS'} # resource : displayed name
        loaded = ', '.join(js_names[r] if r in js_names else r.capitalize()+'JS'
                           for r in resources)

        load_hvjs(logo=p.logo, JS=('holoviews' in resources),
                  message = '%s successfully loaded in this cell.' % loaded)
        for r in [r for r in resources if r != 'holoviews']:
            Store.renderers[r].load_nb(inline=p.inline)

        if resources[-1] != 'holoviews':
            get_ipython().magic(u"output backend=%r" % resources[-1]) # noqa (get_ipython))