Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Push bokeh BoxAnnotation to the background

Tags:

python

bokeh

I have constructed a bokeh plot which I run in a Jupyter notebook. It displays "classic" glyphs, as well as BoxAnnotations that enable me to highlight periods of time depending on status (see image below).

bokeh plot with foreground BoxAnnotations

What annoys me is that the BoxAnnotations seem to always be in the foreground, and therefore prevent users from clearly seeing colors.

I tried to switch the commands to add the annotations and the glyphs, but without success.

Is there any way to push the BoxAnnotation to the background, or are layouts always in the foreground? Is there any other way to achieve the plotting I would like to produce?

like image 638
Pierre Massé Avatar asked Jan 24 '26 17:01

Pierre Massé


1 Answers

You can try adding level="underlay" when you create your BoxAnnotation:

BoxAnnotation(..., level="underlay")

This is a feature of the Bokeh Annotation base class, where you can specify any of the following levels: image, underlay, glyph, guide, annotation, overlay I believe they are in incremental order from background -> foreground.

They have a brief snippet of it in the Plots section of their user-guide. Though I do find the documentation of it to be a little lacking.

like image 62
Cameron Riddell Avatar answered Jan 27 '26 07:01

Cameron Riddell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!