當前位置: 首頁>>代碼示例>>Python>>正文


Python embed.file_html方法代碼示例

本文整理匯總了Python中bokeh.embed.file_html方法的典型用法代碼示例。如果您正苦於以下問題:Python embed.file_html方法的具體用法?Python embed.file_html怎麽用?Python embed.file_html使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在bokeh.embed的用法示例。


在下文中一共展示了embed.file_html方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _output_plot_file

# 需要導入模塊: from bokeh import embed [as 別名]
# 或者: from bokeh.embed import file_html [as 別名]
def _output_plot_file(self, model, idx, filename=None, template="basic.html.j2"):
        if filename is None:
            tmpdir = tempfile.gettempdir()
            filename = os.path.join(tmpdir, f"bt_bokeh_plot_{idx}.html")

        env = Environment(loader=PackageLoader('backtrader_plotting.bokeh', 'templates'))
        templ = env.get_template(template)
        templ.globals['now'] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")

        html = file_html(model,
                         template=templ,
                         resources=CDN,
                         template_variables=dict(
                             stylesheet=self._output_stylesheet(),
                             show_headline=self.p.scheme.show_headline,
                             )
                         )

        with open(filename, 'w') as f:
            f.write(html)

        return filename 
開發者ID:verybadsoldier,項目名稱:backtrader_plotting,代碼行數:24,代碼來源:bokeh.py

示例2: _figure_to_png

# 需要導入模塊: from bokeh import embed [as 別名]
# 或者: from bokeh.embed import file_html [as 別名]
def _figure_to_png(self):
        """Convert figure object to PNG
        Bokeh can only save figure objects as html.
        To convert to PNG the HTML file is opened in a headless browser.
        """
        driver = self._initialize_webdriver()
        # Save figure as HTML
        html = file_html(self.figure, resources=INLINE, title="")
        fp = tempfile.NamedTemporaryFile(
            'w', prefix='chartify', suffix='.html', encoding='utf-8')
        fp.write(html)
        fp.flush()
        # Open html file in the browser.
        driver.get("file:///" + fp.name)
        driver.execute_script("document.body.style.margin = '0px';")
        png = driver.get_screenshot_as_png()
        driver.quit()
        fp.close()
        # Resize image if necessary.
        image = Image.open(BytesIO(png))
        target_dimensions = (self.style.plot_width, self.style.plot_height)
        if image.size != target_dimensions:
            image = image.resize(target_dimensions, resample=Image.LANCZOS)
        return image 
開發者ID:spotify,項目名稱:chartify,代碼行數:26,代碼來源:chart.py

示例3: _figure_to_svg

# 需要導入模塊: from bokeh import embed [as 別名]
# 或者: from bokeh.embed import file_html [as 別名]
def _figure_to_svg(self):
        """
        Convert the figure to an svg so that it can be saved to a file.
        https://github.com/bokeh/bokeh/blob/master/bokeh/io/export.py
        """
        driver = self._initialize_webdriver()
        html = file_html(self.figure, resources=INLINE, title="")

        fp = tempfile.NamedTemporaryFile(
            'w', prefix='chartify', suffix='.html', encoding='utf-8')
        fp.write(html)
        fp.flush()
        driver.get("file:///" + fp.name)
        svgs = driver.execute_script(_SVG_SCRIPT)
        fp.close()

        driver.quit()
        return svgs[0] 
開發者ID:spotify,項目名稱:chartify,代碼行數:20,代碼來源:chart.py

示例4: html

# 需要導入模塊: from bokeh import embed [as 別名]
# 或者: from bokeh.embed import file_html [as 別名]
def html(self, obj, fmt=None, css=None, resources='CDN', **kwargs):
        """
        Renders plot or data structure and wraps the output in HTML.
        The comm argument defines whether the HTML output includes
        code to initialize a Comm, if the plot supplies one.
        """
        plot, fmt =  self._validate(obj, fmt)
        figdata, _ = self(plot, fmt, **kwargs)
        if isinstance(resources, basestring):
            resources = resources.lower()
        if css is None: css = self.css

        if isinstance(plot, Viewable):
            doc = Document()
            plot._render_model(doc)
            if resources == 'cdn':
                resources = CDN
            elif resources == 'inline':
                resources = INLINE
            return file_html(doc, resources)
        elif fmt in ['html', 'json']:
            return figdata
        else:
            if fmt == 'svg':
                figdata = figdata.encode("utf-8")
            elif fmt == 'pdf' and 'height' not in css:
                _, h = self.get_size(plot)
                css['height'] = '%dpx' % (h*self.dpi*1.15)

        if isinstance(css, dict):
            css = '; '.join("%s: %s" % (k, v) for k, v in css.items())
        else:
            raise ValueError("CSS must be supplied as Python dictionary")

        b64 = base64.b64encode(figdata).decode("utf-8")
        (mime_type, tag) = MIME_TYPES[fmt], HTML_TAGS[fmt]
        src = HTML_TAGS['base64'].format(mime_type=mime_type, b64=b64)
        html = tag.format(src=src, mime_type=mime_type, css=css)
        return html 
開發者ID:holoviz,項目名稱:holoviews,代碼行數:41,代碼來源:renderer.py

示例5: save_png

# 需要導入模塊: from bokeh import embed [as 別名]
# 或者: from bokeh.embed import file_html [as 別名]
def save_png(model, filename, template=None, template_variables=None):
    """
    Saves a bokeh model to png

    Arguments
    ---------
    model: bokeh.model.Model
      Model to save to png
    filename: str
      Filename to save to
    template:
      template file, as used by bokeh.file_html. If None will use bokeh defaults
    template_variables:
      template_variables file dict, as used by bokeh.file_html
    """
    from bokeh.io.webdriver import webdriver_control
    if not state.webdriver:
        state.webdriver = webdriver_control.create()

    webdriver = state.webdriver

    try:
        if template:
            def get_layout_html(obj, resources, width, height):
                return file_html(
                    obj, resources, title="", template=template,
                    template_variables=template_variables,
                    suppress_callback_warning=True, _always_new=True
                )
            old_layout_fn = bokeh.io.export.get_layout_html
            bokeh.io.export.get_layout_html = get_layout_html
        export_png(model, filename=filename, webdriver=webdriver)
    except Exception:
        raise
    finally:
        if template:
            bokeh.io.export.get_layout_html = old_layout_fn


#---------------------------------------------------------------------
# Public API
#--------------------------------------------------------------------- 
開發者ID:holoviz,項目名稱:panel,代碼行數:44,代碼來源:save.py


注:本文中的bokeh.embed.file_html方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。