[bokeh] Interactively adding lines to figure


The easy way of doing this is to you a CustomJS callback to find the
line that you want to display and change it's alpha to, say, 1.0 and
find the lines that you don't want to display and change their alpha to
0 (so they are invisible).

If you have a lot of potential regions it will require a little trickery
to make these nicely accessible in the CustomJS callback.

I would use the same trick I did in GapMinder. Check out the detailed
notes here:

In particular the notes around "In [11]"

Some related code - a callback where I change the alpha:

FWIW This seems annoyingly difficult in Bokeh at the moment and there
are open issues to make this kind of thing easy to do.


Sarah Bird


On 1/29/16 1:54 PM, [email protected] wrote:


I want to plotting lines corresponding to the input user will give
through InputText

the code snippet, example.py

region = pd.read_csv("region.csv", encoding="utf-8").set_index("plo_region")
fig = figure(plot_width=700, plot_height=500,
y_axis_type="log",y_range=(10**-2, 10**3))

# callback template
def callback_template(new, table, ts_length):
    # whatever behavior

def callback_region(attr, old, new):
    callback_template(new, region, TS_LENGTH)

    # what to add line in callback function
    fig.line(x=[1,2,3], y=[1,2,3], legend="sdfds",color="black")
    curdoc().add_root(hplot(inputs, fig))

textInput_region = TextInput(value="", title="region:")
textInput_region.on_change("value", callback_region)

controls = [textInput_region]
inputs = HBox(VBoxForm(controls), width=300)

# put the button and plot in a layout and add to the document
curdoc().add_root(hplot(inputs, fig))

so if the user gives "Berlin, Hamburg" in TextInput box, it will trigger
the callback function and plotting two lines on the figure. Instead, if
the user gives "Berlin, Hamburg, Hannover", it will plot three lines.

You received this message because you are subscribed to the Google
Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to [email protected]
<mailto:[email protected]>.
To post to this group, send email to [email protected]
<mailto:[email protected]>.
To view this discussion on the web visit
For more options, visit https://groups.google.com/a/continuum.io/d/optout.