【问题标题】:Removing padding or margins from Bokeh Figures从散景图中删除填充或边距
【发布时间】:2017-01-23 13:30:51
【问题描述】:

是否可以消除散景图形两侧的填充(或边距)? 我一直在看各种数字,他们的左边似乎都有这个空白区域。我也试过改变边界 例如:s1.min_border_left = 0 or change it to s1.min_border_left = 40

但它似乎并没有完成这项工作,它改变了边框,但不知何故,似乎有一个固定且不可更改的填充,我想摆脱的区域的一个例子: Image example 那么是否有可能摆脱它而只将图形粘在浏览器的左侧?

Bokeh Figures and Borders

【问题讨论】:

    标签: python bokeh figure


    【解决方案1】:

    如果使用散景服务器,您可以添加一个带有类似这样的外部 css 表来修改边距。

    html, body {
        display: block;
        margin: 0 auto;
        width: 99%;
    } 
    

    【讨论】:

      【解决方案2】:

      打开生成的 HTML 页面并将宽度 90% 替换为 100%

      【讨论】:

        【解决方案3】:

        根据其他答案,这里是 sn-p 可能会派上用场:

        import os
        import re
        import tempfile
        import webbrowser
        import time
        
        from bokeh.io import output_file, save
        
        
        def save_bokeh_nomargins(plot, filename):
            """
            Saves a bokeh plot/layout without having the left margin.
            """
            # Strategy:
            #  1. save the plot to a temp file
            #  2. change the offending line of code
            #  3. save the result to the destination file
            ftemp = tempfile.mktemp()
            try:
                output_file(ftemp)
                save(plot)
                with open(ftemp) as ftemph, open(filename, "w") as fouth:
                    fouth.write(re.sub("width: 90%;", "width: 100%;", ftemph.read(), count=1))
            finally:
                    os.remove(ftemp)
        
        
        def show_bokeh_nomargins(plot):
            """
            Displays a bokeh plot/layout without having the left margin.
            """
            ftemp = tempfile.mktemp()
            try:
                save_bokeh_nomargins(plot, ftemp)
                webbrowser.open(ftemp)
                time.sleep(1)
            finally:
                os.remove(ftemp)
        

        我应该注意,这有点 hacky,如果您在文件中的其他任何地方有 width: 90%,它可能会出错。

        【讨论】:

          猜你喜欢
          • 2012-03-28
          • 1970-01-01
          • 1970-01-01
          • 2016-03-25
          • 1970-01-01
          • 2016-04-09
          • 1970-01-01
          • 2015-07-14
          相关资源
          最近更新 更多