Hello, folks!
As I’ve mentioned in this forum on prior posts, I’ve been translating my team’s plotting code from (A) server-side python capture and rendering, to (B) server-side capture only and client-side rendering with BokehJS and websockets.
As promised here, I’ve tracked the main differences I’ve encountered between the expected usage in Python vs BokehJS, based on the available documentation. I’ve also put together a collection of minimal examples and workarounds (where possible) loosely based on the documentation’s original “minimal example”.
Issues in 2.3.0 and 2.2.3:
Descriptions here, links below.
-
var plot = new Bokeh.Plotting.figure({title:"some title"})
replaces plot.title (Title() object by default) with provided string. Python casts string to the underlying Title() object. -
Bokeh.Plotting.gridplot()
does not seem to inherit sizing_mode from underlying plots, or default is different. To match expected behavior withsizing_mode:stretch_width
(for example) from Python flavor, sizing mode must be explicitly stated for both the figure() and the gridplot() objects - Palette is available under Bokeh.Charts but not under Bokeh.Plotting; to use with, say, image(), the palette argument must be provided as a color string array, rather than as a string.
- Setting
plot.x_range.start
andplot.x_range.end
, orplot.x_range.range_padding
to adjust whitespace around glyphs on X axis is not persistent across “resets”; to match expected behavior from Python output, setplot.x_range.range_padding
andplot.x_range._initial_range_padding
. (Same for Y axis) - plot.line([0,1],[0,1],{name:“the_name”}) sets renderer.glyph.name, rather than renderer.name; the latter seems to be used for HoverTool under ‘$name’
-
Bokeh.Widgets.Div()
does not includediv.toolbar.tools
(== []
) to facilitate using in a customBokeh.Plotting.gridplot()
; or gridplot() fails to check property exists before accessing; throwsUncaught TypeError: Cannot read property 'tools' of undefined
Links to minimal code for the issues above:
The code samples below include comment blocks to quickly switch between 2.2.3 and 2.3.0, as well as some additional commentary in context.
-
bokehjs_title :
shows both methods of title creation discussed above, with a button for dynamic updates to the title text -
bokehjs_sizing_mode :
shows the behavior for bothsizing_mode
approaches above -
bokehjs_palette :
shows three approaches to palette selection forBokeh.Plotting.image()
-
bokehjs_range_padding :
shows range padding behavior across resets; click reset on the figure to test behavior -
bokehjs_glyph_name :
shows name inheritance behavior; use hover tool to inspect name on both lines -
bokehjs_div_tools :
shows a gridplot composed of a Div widget and a figure; comment Div toolbar definition to trigger gridplot failure
Fixed in 2.3.0
The following was an issue in 2.2.3 but behaves as expected in 2.3.0; recorded here for reference.
- Setting
plot.frame_width
while usingsizing_mode:'fixed'
does not resize canvas as expected; takes effect only after changingplot.width
orplot.plot_width
. Test: use frame_width, then (1) do nothing to render with default 600px with, or (2) set plot_width = null to make frame_width take over.
bokehjs_frame_width :
shows two plots usingsizing_mode:'fixed'
andframe_width
; only one triggers size adjustment manually by changingplot_width
after the figure is created.
@Bryan and team, I’m not sure these necessarily warrant long-term expansion to the docs as I had suggested in the original thread linked above (also here), since I expect some of this behavior might need to be updated; but they certainly warrant documenting for current users, I think. Is there a good place in the docs for what amounts to temp examples? Or, if you believe these should be added to the docs anyway, I’ll be happy to draft an update on GitHub. I await your guidance on how best to share this with the wider bokeh user community!