简体   繁体   中英

How to draw in a python jupyter notebook?

I ultimately want to be able to draw over the top of other images, and then save the drawing data to be viewed later.

I've tried working with matplotlib. I got it pretty functional, as described here , but run into a lot of issues since I can't have it open in another window, and when it displays inline, the callback events don't fire properly.

I'm connecting to a remote jupyter server, so I think everything needs to be inline. I've read some stuff about bokeh, and it seems like it might be useful, but I don't know where to start.

This seems pretty easy with javascript, but I cant figure out how to get javasctipt to run in jupyter. At least not when its more than just a line or 2.

I think with bokeh you are already on the right track. For scientific visualization, graphic libraries such as holoviews are quite famous, as they work on a high abstraction level and allow to create interactive diagrams. for plotting in an existing plot it would look basically like this:

import holoviews as hv
hv.extension('bokeh')
from holoviews import opts
from bokeh.plotting import show, output_file

Curve_opts = {'width':700, 'height':400, 'bgcolor':'#FFFFFF', 
       'tools':TOOLS, 'line_width':1.2,}

plot = hv.Curve(data=df, kdims=['col_x','col_y'], vdims=['value_in_tag'], label='legend 1')\
     * hv.Scatter(data=df, kdims=['col_x','col_y'], vdims=['col_color'], label='legend 2')   
# with '*' you plot into the same frame of a layout 

plot = plot.relabel("Diagram Title")

plot.opts(opts.Curve(**Curve_opts ))        # provide a dict to customize output
hv.save(plot, 'Filename.png', fmt='png')    # save as png to be used in an article
output_file('Filename.html')                # interactive diagram for web-publishing
show(hv.render(plot))                       # workaround as spyder doesn't render hv 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM