本节向您展示如何执行此操作:
https://docs.bokeh.org/en/latest/docs/user_guide/styling.html#selected-and-unselected-glyphs https://docs.bokeh.org/en/latest/docs/user_guide/styling.html#selected-and-unselected-glyphs
您需要设置selection_glyph
and nonselection_glyph
将圆形渲染器转换为具有所需属性的字形。
在手册中,通过在p.circle(..., name="mycircle")
调用然后使用renderer = p.select(name="mycircle")
。您还可以在渲染器返回时保存对渲染器的引用p.circle(...)
功能:renderer = p.circle('t', 'Eu', source=source, line_color=None)
.
一旦获得了渲染器的引用,您就可以分配字形:
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)