从散景图中删除填充或边距

时间:2017-01-23 13:30:52

标签: python bokeh figure

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

但它似乎没有做到这一点,它改变了边框,但不知何故似乎有一个固定的填充,而不是可变的,我想摆脱的区域的一个例子: Image example 那么有可能摆脱它,只是让数字贴在浏览器的左侧吗?

Bokeh Figures and Borders

3 个答案:

答案 0 :(得分:0)

打开生成的HTML页面,用100%

替换宽度90%

答案 1 :(得分:0)

如果使用散景服务器,您可以添加外部css表格来修改边距。

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

答案 2 :(得分:0)

基于其他答案,这里的代码片段可能会派上用场:

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)

我应该注意,这有点笨拙,如果您在文件中的任何其他位置width: 90%,则可能会出错。