Bokeh: Support changing any line property on selection or hover

Created on 20 Dec 2016  路  4Comments  路  Source: bokeh/bokeh

Currently, only the alpha and color properties of lines can be modified on selection or hover (eg, via keyword arguments to plotting methods such as selection_line_alpha, selection_line_color, etc). It would be nice if we could change other line properties as well on selection or hover, such as width or line style (eg dashed). My use case involves plotting climate data over a map (via image()) and then plotting separate information based on the selected subregion on the map which are patches that are derived from a GeoJSON file. I would like to be able to modify these line properties to put emphasis on the selected subregion on the map.

invalid feature

Most helpful comment

the keyword arguments are provided for color and alpha as conveniences, because those are the most common. But it's always possible to update the relevant glyphs directly for other properties:

from bokeh.io import output_file, show
from bokeh.plotting import figure

output_file("styling_selections.html")

plot = figure(plot_width=400, plot_height=400, tools="tap", title="Select a circle")
renderer = plot.circle([1, 2, 3, 4, 5], [2, 5, 8, 2, 7], size=50,

                       # set visual properties for selected glyphs
                       selection_fill_color="pink",

                       # set visual properties for non-selected glyphs
                       nonselection_fill_alpha=0.2,
                       nonselection_fill_color="blue",
                       nonselection_line_color="firebrick",
                       nonselection_line_alpha=1.0)

# Change line width and dashing here
renderer.selection_glyph.line_width = 5
renderer.nonselection_glyph.line_dash = [5, 5]

show(plot)

screen shot 2016-12-20 at 3 53 59 pm

All 4 comments

the keyword arguments are provided for color and alpha as conveniences, because those are the most common. But it's always possible to update the relevant glyphs directly for other properties:

from bokeh.io import output_file, show
from bokeh.plotting import figure

output_file("styling_selections.html")

plot = figure(plot_width=400, plot_height=400, tools="tap", title="Select a circle")
renderer = plot.circle([1, 2, 3, 4, 5], [2, 5, 8, 2, 7], size=50,

                       # set visual properties for selected glyphs
                       selection_fill_color="pink",

                       # set visual properties for non-selected glyphs
                       nonselection_fill_alpha=0.2,
                       nonselection_fill_color="blue",
                       nonselection_line_color="firebrick",
                       nonselection_line_alpha=1.0)

# Change line width and dashing here
renderer.selection_glyph.line_width = 5
renderer.nonselection_glyph.line_dash = [5, 5]

show(plot)

screen shot 2016-12-20 at 3 53 59 pm

This is also explained in more detail in the docs:

http://bokeh.pydata.org/en/latest/docs/user_guide/styling.html#glyphs

Thank you for this. Didn't realize that these properties could be modified directly from the renderer attributes.

@agoodm If there is anything or anywhere that can be updated in the docs to make this easier to find or understand, please let us know

Was this page helpful?
0 / 5 - 0 ratings