forked from bokeh/bokeh
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhover.py
More file actions
50 lines (38 loc) · 1.23 KB
/
Copy pathhover.py
File metadata and controls
50 lines (38 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# You must first run "bokeh serve" to view this example
import itertools
import numpy as np
from bokeh.models import HoverTool
from bokeh.plotting import ColumnDataSource, figure, show, output_server
TOOLS="crosshair,pan,wheel_zoom,box_zoom,reset,hover,previewsave"
xx, yy = np.meshgrid(range(0,101,4), range(0,101,4))
x = xx.flatten()
y = yy.flatten()
N = len(x)
inds = [str(i) for i in np.arange(N)]
radii = np.random.random(size=N)*0.4 + 1.7
colors = [
"#%02x%02x%02x" % (int(r), int(g), 150) for r, g in zip(50+2*x, 30+2*y)
]
source = ColumnDataSource(data=dict(
x=x,
y=y,
radius=radii,
colors=colors,
foo=list(itertools.permutations("abcdef"))[:N],
bar=np.random.normal(size=N),
))
p = figure(title="Hoverful Scatter", tools=TOOLS)
p.circle(x, y, radius=radii, source=source,
fill_color=colors, fill_alpha=0.6, line_color=None)
p.text(x, y, text=inds, alpha=0.5, text_font_size="5pt",
text_baseline="middle", text_align="center")
hover = p.select_one(HoverTool).tooltips = [
("index", "$index"),
("(x,y)", "($x, $y)"),
("radius", "@radius"),
("fill color", "$color[hex, swatch]:fill_color"),
("foo", "@foo"),
("bar", "@bar"),
]
output_server("hover")
show(p) # open a browser