How to control the z-order of glyphs in Bokeh?
Some level of control is possible by changing the .level
attribute of a patch.
For example, the following code produces a red patch above the blue dots:
from bokeh.io import output_notebook, show
from bokeh.plotting import figure
output_notebook()
p = figure(title='one')
p.scatter([1, 2, 3, 4], [1, 2, 1, 3], size=20)
patch = p.varea(x=[1, 2, 3, 4], y1=[0, 1, 0, 2.5], y2=[1.5, 1.75, 1.5, 3.5], color='red', alpha=0.75)
show(p)
If we want to control the patch z order, we need to modify its level
attribute to one of the following: image, underlay, glyph, annotation or overlay. In our case, we need "underlay"
p = figure(title='one')
p.scatter([1, 2, 3, 4], [1, 2, 1, 3], size=20)
patch = p.varea(x=[1, 2, 3, 4], y1=[0, 1, 0, 2.5], y2=[1.5, 1.75, 1.5, 3.5], color='red', alpha=0.75)
patch.level = 'underlay'
show(p)