How to set properties of selected / unselected glyphs in bokeh

I have a data set consisting of time series of several observables, and I would like to use bokeh to see the phase diagram at different points in the time series. I want to know how to change the properties of selected or unselected glyphs (in this case, I would like to reduce the alpha of unselected points or change the color of the selected).

The code below creates the interface that I want on an ipython laptop, and is based on an example in the user guide http://bokeh.pydata.org/en/0.10.0/docs/user_guide/interaction.html#linked-brushing . I cannot find any obvious installation options, and I would not want to learn javascript for this.

import numpy as np from pandas import DataFrame from bokeh.plotting import figure, output_notebook, show, gridplot from bokeh.models import ColumnDataSource, widgets def znzt_ts():#, plot_antisym=False, **kwargs): t = np.arange(1000) Eu = np.sin(t * np.pi/10) + np.random.random(1000) Ez = np.cos(t * np.pi/10) + np.random.random(1000) ts = DataFrame({'t': t, 'Eu': Eu, 'Ez': Ez}) tools = 'box_zoom,pan,reset,save,box_select' source = ColumnDataSource(data=ts) original_source = ColumnDataSource(data=ts) p1 = figure(plot_width=300, plot_height=300, tools=tools) p2 = figure(plot_width=300, plot_height=300, tools=tools,) p1.circle('t', 'Eu', source=source, size=1) p2.circle('Eu', 'Ez', source=source, size=1) return gridplot([[p1, p2]]) gp = znzt_ts() output_notebook() show(gp) 
+5
source share
2 answers

The Adam link in his comment shows you how to do this: you need to set selection_glyph and nonselection_glyph your circle renderers to glyphs with the desired properties.

The visualization guide refers to naming in a call to p.circle(..., name="mycircle") , and then using renderer = p.select(name="mycircle") . You can also save the link to the renderer when it is returned by p.circle(...) : renderer = p.circle('t', 'Eu', source=source, line_color=None) .

Once you have a link to the renderer, you can assign glyphs:

 renderer.selection_glyph = Circle(fill_color='firebrick', line_color=None) renderer.nonselection_glyph = Circle(fill_color='#1f77b4', fill_alpha=0.1, line_color=None) 

 import numpy as np from pandas import DataFrame from bokeh.plotting import figure, output_notebook, show, gridplot from bokeh.models import ColumnDataSource, widgets from bokeh.models.glyphs import Circle def znzt_ts():#, plot_antisym=False, **kwargs): t = np.arange(1000) Eu = np.sin(t * np.pi/10) + np.random.random(1000) Ez = np.cos(t * np.pi/10) + np.random.random(1000) ts = DataFrame({'t': t, 'Eu': Eu, 'Ez': Ez}) tools = 'box_zoom,pan,reset,save,box_select' source = ColumnDataSource(data=ts) original_source = ColumnDataSource(data=ts) selection_glyph = Circle(fill_color='firebrick', line_color=None) nonselection_glyph = Circle(fill_color='#1f77b4', fill_alpha=0.1, line_color=None) p1 = figure(plot_width=300, plot_height=300, tools=tools) r1 = p1.circle('t', 'Eu', source=source, line_color=None) r1.selection_glyph = selection_glyph r1.nonselection_glyph = nonselection_glyph p2 = figure(plot_width=300, plot_height=300, tools=tools) r2 = p2.circle('Eu', 'Ez', source=source, line_color=None) r2.selection_glyph = selection_glyph r2.nonselection_glyph = nonselection_glyph return gridplot([[p1, p2]]) gp = znzt_ts() output_notebook() show(gp) 
+3
source

To completely remove unselected glyphs, you can use:

 fig = Figure() c = fig.circle(x='x', y='y', source=source) c.nonselection_glyph.visible = False 
0
source

Source: https://habr.com/ru/post/1237876/


All Articles