
Hi there,
The user needs to be able to change the order of renderers instead of just click them on and off. Ideally they could simply drag and drop their order in the legend, which would then change the render order in the plot. Does Bokeh have an option like this?
Ive tried re-ordering with a button (see MRE below). But i would like the user to be able to set each render order instead of a basic swap like this.
def MakePLot():
from bokeh.plotting import figure
import numpy as np
# Generate random data
x = np.random.random(size=100) * 10
y = np.random.random(size=100) * 10
y1 = np.random.random(size=100) * 10
y2 = y1 + np.random.uniform(1, 3, size=100)
p = figure(width=800, height=250)
p.title.text = 'Click on legend entries to hide the corresponding lines'
# Add scatter and area glyphs
scatter = p.scatter(x, y, color='blue', legend_label='blue scatter', name="Blue Points")
scatter = p.scatter(x*1.1, y*0.9, color='green', size=15, legend_label='green scatter', name="Green Points")
area = p.varea(x=x, y1=y1, y2=y2, fill_color='red', legend_label='area', name="Red Area")
p.legend.location = "top_left"
p.legend.click_policy="hide"
return p
def Add_Render_Order_Button(p):
from bokeh.models import CustomJS, Button
# JavaScript code to reorder the renderers list
code = """
var reorderedRenderers = [plot.renderers[2], plot.renderers[1], plot.renderers[0]];
plot.renderers = reorderedRenderers;
"""
callback = CustomJS(args=dict(plot=p), code=code)
button = Button(label="Swap Red Area Render Order with Points", button_type="success")
button.js_on_click(callback)
return button
from bokeh.layouts import column
from bokeh.plotting import show, output_notebook
p = MakePLot()
button = Add_Render_Order_Button(p)
output_notebook()
layout = column(button, p)
show(layout)
Cheers,
Eric




