散景:循环生成图形,输出图形的文件大小不断增加 [英] Bokeh: Generating graphs in a loop, the output graph's file sizes keep increasing

查看:58
本文介绍了散景:循环生成图形,输出图形的文件大小不断增加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用bokeh循环绘制100个图形文件.

I'm using bokeh to plot 100 graph files in a loop.

for k in files:
    # Read the log file data into a df.
    log_file_name = str(k) + ".csv" 
    logged_data = pd.read_csv("csv/"+log_file_name, parse_dates=["dttm_utc"], date_parser=dateparse)

    new_logged_data = logged_data.set_index("dttm_utc")
    mean_data = new_logged_data.resample("3D", how=[np.mean])

    # Extract the energy values and time stamps out into two ds.
    energy_data = mean_data["value"]["mean"]
    time_data = mean_data.index

    # Plotting
    output_file("csv/plots/" + log_file_name + ".html", title="Energy Consumption")

    p = figure(width=1600, height=350, x_axis_type="datetime")
    p.line(time_data, energy_data, color='navy', legend='energy')
    #p.circle(time_data, energy_data, size=2, color='navy', alpha=0.2, legend='energy')

    p.title = log_file_name + "   INDUSTRY: " + i + "   SUB-INDUSTRY: " + j)
    p.title_text_font_size = '10pt'
    p.legend.location = "top_left"
    p.grid.grid_line_alpha=0
    p.xaxis.axis_label = 'Time'
    p.yaxis.axis_label = 'Energy (kWh)'
    p.ygrid.band_fill_color="olive"
    p.ygrid.band_fill_alpha = 0.1
    save(p)

    count += 1
    print str(count) + " " + log_file_name

我要注意的是,每个图形文件的大小都大于前一个文件的大小(请看截图1).

What I'm noticing is that the size of every graph file is more than it's previous one (Please look at the Screenshot 1).

如果重新生成全部100张图,则文件大小与上一次迭代不同(屏幕截图2).

If regenerate all 100 graphs the file sizes are not same as the previous iteration (Screenshot 2).

我还注意到一个奇怪的事情是,如果我重新启动Jupyter笔记本的内核,则文件大小将重置为最小(屏幕截图3),如果我重复所有100个文件的重新生成,它们将继续增加.

A strange thing I have also noticed is that if I restart the kernel of my Jupyter notebook then the file sizes reset to the least (Screenshot 3), once again if I repeat regeneration of all 100 files they keep increasing.

用于生成这些图的样本数量始终相同,那么为什么文件大小不同?我是否忘记执行某些操作,例如关闭文件?任何帮助!

The number of samples for generating these graphs is always same then why are file size different? Am I forgetting to do something, like closing the file? Any help!

推荐答案

从Bokeh 0.11.1 开始,有时需要使用 reset_output 函数显式清除输出.:

As of Bokeh 0.11.1 it is sometimes necessary to explicitly clear the output with the reset_output function:

from bokeh.plotting import reset_output

每次迭代中的

reset_output()

这篇关于散景:循环生成图形,输出图形的文件大小不断增加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆