具有不同工具提示的多个散景图
multiple bokeh plots with different tooltips
这是我想要实现的目标的最小示例
from bokeh.plotting import ColumnDataSource, figure, output_file, save
output_file("test_plot.html")
source = ColumnDataSource(data=dict(
x=[1,3],
y=[3,7],
label=['a','b']
))
TOOLTIPS = [ ("label", "@label")]
p = figure(plot_width=400, plot_height=400, tooltips=TOOLTIPS, title="plot")
p.circle('x', 'y', size=20,fill_alpha=0.5, source=source)
source = ColumnDataSource(data=dict(
x=[0],
y=[0],
info1 = ['info 1'],
info2 = ['info 2']
))
p.circle('x','y', size=10,fill_alpha=0.5, source=source)
save(p)
并且我需要在(0,0)处的散点添加不同的TOOLTIPS,它可以显示info1和info2。
您必须手动创建工具。请注意,它还会在工具栏上显示多个工具。
from bokeh.models import HoverTool
from bokeh.plotting import ColumnDataSource, figure, save
source = ColumnDataSource(data=dict(x=[1, 3], y=[3, 7],
label=['a', 'b']))
p = figure(plot_width=400, plot_height=400, title="plot")
circle1 = p.circle('x', 'y', size=20, fill_alpha=0.5, source=source)
source = ColumnDataSource(data=dict(x=[0], y=[0],
info1=['info 1'], info2=['info 2']))
circle2 = p.circle('x', 'y', size=10, fill_alpha=0.5, source=source)
p.add_tools(HoverTool(renderers=[circle1],
tooltips=[('label', '@label')]),
HoverTool(renderers=[circle2],
tooltips=[('info1', '@info1'),
('info2', '@info2')]))
save(p)
这是我想要实现的目标的最小示例
from bokeh.plotting import ColumnDataSource, figure, output_file, save
output_file("test_plot.html")
source = ColumnDataSource(data=dict(
x=[1,3],
y=[3,7],
label=['a','b']
))
TOOLTIPS = [ ("label", "@label")]
p = figure(plot_width=400, plot_height=400, tooltips=TOOLTIPS, title="plot")
p.circle('x', 'y', size=20,fill_alpha=0.5, source=source)
source = ColumnDataSource(data=dict(
x=[0],
y=[0],
info1 = ['info 1'],
info2 = ['info 2']
))
p.circle('x','y', size=10,fill_alpha=0.5, source=source)
save(p)
并且我需要在(0,0)处的散点添加不同的TOOLTIPS,它可以显示info1和info2。
您必须手动创建工具。请注意,它还会在工具栏上显示多个工具。
from bokeh.models import HoverTool
from bokeh.plotting import ColumnDataSource, figure, save
source = ColumnDataSource(data=dict(x=[1, 3], y=[3, 7],
label=['a', 'b']))
p = figure(plot_width=400, plot_height=400, title="plot")
circle1 = p.circle('x', 'y', size=20, fill_alpha=0.5, source=source)
source = ColumnDataSource(data=dict(x=[0], y=[0],
info1=['info 1'], info2=['info 2']))
circle2 = p.circle('x', 'y', size=10, fill_alpha=0.5, source=source)
p.add_tools(HoverTool(renderers=[circle1],
tooltips=[('label', '@label')]),
HoverTool(renderers=[circle2],
tooltips=[('info1', '@info1'),
('info2', '@info2')]))
save(p)