Python Bokeh绘图:输出文件正在追加而不是覆盖

Python Bokeh绘图:输出文件正在追加而不是覆盖,python,python-3.x,plot,data-visualization,bokeh,Python,Python 3.x,Plot,Data Visualization,Bokeh,下面的代码运行良好,但最终它开始在每次执行代码时在同一HTML文件中追加多个绘图。这是一个奇怪的行为,根据Bokeh文档,函数output\u file()应该覆盖HTML文件,而不是附加它 如何防止每次执行脚本时输出文件附加多个绘图 我的代码:[汇编函数,更大项目的一部分] from bokeh.models import (HoverTool, ColumnDataSource, Titl

下面的代码运行良好,但最终它开始在每次执行代码时在同一HTML文件中追加多个绘图。这是一个奇怪的行为,根据Bokeh文档,函数
output\u file()
应该覆盖HTML文件,而不是附加它

如何防止每次执行脚本时输出文件附加多个绘图

我的代码:[汇编函数,更大项目的一部分]

from bokeh.models import (HoverTool,
                          ColumnDataSource,
                          Title,
                          DatetimeTickFormatter)
import pandas as pd
from bokeh.io import show, output_file
from bokeh.plotting import figure


def assembly_chart(df, complements):
    """function to assembly the chart"""

    output_file("movigrama_chart.html")

    source = ColumnDataSource(df)

    p = figure(x_axis_type='datetime',
               x_axis_label='days of moviment',
               y_axis_label='unities movimented',
               plot_width=1230,
               plot_height=500,
               active_scroll='wheel_zoom')

    p.vbar(x='DT',
           bottom=0,
           top='STOCK',
           width=pd.Timedelta(days=1),
           fill_alpha=0.4,
           color='#99d8c9',
           source=source)

    p.vbar(x='DT',
           bottom=0,
           top='SOMA_SAI',
           width=pd.Timedelta(days=1),
           fill_alpha=0.8,
           color='crimson',
           source=source)

    p.vbar(x='DT',
           bottom=0,
           top='SOMA_ENTRA',
           width=pd.Timedelta(days=1),
           fill_alpha=0.8,
           color='seagreen',
           source=source)

    p.add_layout(Title(text=complements['warehouse'],
                       text_font='helvetica',
                       text_font_size='10pt',
                       text_color='orangered',
                       text_alpha=0.5,
                       align='center',
                       text_font_style="italic"), 'above')
    p.add_layout(Title(text=complements['product'],
                       text_font='helvetica',
                       text_font_size='10pt',
                       text_color='orangered',
                       text_alpha=0.5,
                       align='center',
                       text_font_style="italic"), 'above')
    p.add_layout(Title(text='Movigrama Endicon',
                       text_font='helvetica',
                       text_font_size='16pt',
                       text_color='orangered',
                       text_alpha=0.9,
                       align='center',
                       text_font_style="bold"), 'above')

    p.x_range.range_padding = 0.1
    p.y_range.range_padding = 0.1

    p.outline_line_width = 4
    p.outline_line_alpha = 0.1
    p.outline_line_color = 'orangered'

    p.axis.major_label_text_color = 'gray'
    p.axis.major_label_text_font_style = 'bold'

    p.axis.axis_label_text_color = 'gray'
    p.axis.axis_label_text_font_style = 'bold'

    p.axis.major_tick_out = 10
    p.axis.minor_tick_in = -3
    p.axis.minor_tick_out = 6
    p.axis.minor_tick_line_color = 'gray'

    p.xaxis.formatter = DatetimeTickFormatter(
                days=['%d/%m'],
                months=['%m/%Y'],
                years=['%Y'])

    # iniciate hover object
    hover = HoverTool()
    hover.mode = 'vline'  # activate hover by vertical line
    hover.tooltips = [("IN", "@SOMA_ENTRA"),
                      ("OUT", "@SOMA_SAI"),
                      ("STOCK", "@STOCK"),
                      ("DT", "@DT{%d/%m/%Y}")]
    # use 'datetime' formatter for 'DT' field
    hover.formatters = {"DT": 'datetime'}
    p.add_tools(hover)

    show(p)
output\u file()
函数应该负责处理它,每次执行时都会覆盖HTML文件。至少这是
bokeh.io
文档中所写的

警告

每次保存时(例如每次)都会覆盖此输出文件 调用show()或save()

因此,如果你面对这个问题,解决方法很简单。您只需从bokeh.io导入
reset_输出
,然后在调用
output_文件
函数后调用它

from bokeh.io import reset_output

[...code here...]

output_file("filename.html")
reset_output()

[...more code here...]

这确实解决了问题。我最近也看到了同样的行为,奇怪的是,它在没有reset_输出的情况下工作(就像它应该的那样)。我想知道这个问题是否是针对bokeh版本的?我在bokeh 0.13.0中看到了这一点