Bokeh: Generating graphs in a loop, the output graph's file sizes keep increasing
<p>I'm using bokeh to plot 100 graph files in a loop.</p>

<pre><code>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
</code></pre>

<p>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).</p>

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

<p>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.</p>

<p>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!</p>

<p><a href="https://i.stack.imgur.com/drWuN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/drWuN.png" alt="Screenshot 1"></a>
<a href="https://i.stack.imgur.com/NtKB2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NtKB2.png" alt="Screenshot 2"></a>
<a href="https://i.stack.imgur.com/WEOz0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WEOz0.png" alt="Screenshot 3"></a></p>