Save Drawing from FreehandDraw Tool with Colab

Hello everyone,

Please take a look at this Google Colab file: Google Colab

The Bokeh/HoloView code is as follows:

import holoviews as hv
from holoviews import opts
from holoviews import streams
%env HV_DOC_HTML=true
hv.extension('bokeh')
path = hv.Path([])
freehand = hv.streams.FreehandDraw(source=path, num_objects=3)

path.opts(
    opts.Path(active_tools=['freehand_draw'], height=400, line_width=10, width=400))

hv.save(path, 'fig1.png', backend='matplotlib')

I am attempting to sketch a prediction of a curve onto an empty x-y coordinate system and save the resulting figure as a png to be called back for later use. However, I do not want to use the “Save” tool, since this sends a download of the png to the “Downloads” folder on my computer.

In the Colab file provided, when hv.save is run, the image that gets saved is the figure but before I have drawn anything on it.

In other words, the line that I am drawing on the output is not saving to the png.

Any help would be great.

Thanks.

HI @UConnPhysicsLabTech although Holoviews is built on Bokeh, it is a not the same tool. This question should probably go on the Holoviews Discourse, especially given the non-Bokeh backend that is specified for the save (e.g. I have no idea what transformations that entails or how it is done)

Hello Bryan,

Thanks for your response. Is it possible to do this with Bokeh instead of HoloViews?

If the preamble has be rewritten that’s totally okay.

Thanks.

Best,

< post edited to remove PII >

I would expect if you called Bokeh’s export_png in a Bokeh server app, then the exact current state of the plot, including any annotations, would be included in the output. There was another question just recently about basically the same situation, saving an “updated” plot from a Bokeh server app.

However, it occurs to me the notebook might be problematic. If this is not an embedded Bokeh server app, then the updates from the edit tool only exist on the JS side, they are never synchronized back to the Python side. But the Python state is what would be the input for export_png. So in that case I would not expect the annotation to be included.