forked from realpython/materials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinked-selection.py
More file actions
70 lines (59 loc) · 1.7 KB
/
Copy pathlinked-selection.py
File metadata and controls
70 lines (59 loc) · 1.7 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Bokeh Libraries
from bokeh.plotting import figure, show
from bokeh.io import output_file
from bokeh.models import (
ColumnDataSource,
CategoricalColorMapper,
NumeralTickFormatter,
)
from bokeh.layouts import gridplot
# Output inline in the notebook
output_file(
"phi-gm-linked-selections.html", title="76ers Percentages vs. Win-Loss"
)
# Store the data in a ColumnDataSource
gm_stats_cds = ColumnDataSource(phi_gm_stats_2) # noqa
# Create a CategoricalColorMapper that assigns specific
# colors to wins and losses
win_loss_mapper = CategoricalColorMapper(
factors=["W", "L"], palette=["Green", "Red"]
)
# Specify the tools
toolList = ["lasso_select", "tap", "reset", "save"]
# Create a figure relating the percentages
pctFig = figure(
title="2PT FG % vs 3PT FG %, 2017-18 Regular Season",
plot_height=400,
plot_width=400,
tools=toolList,
x_axis_label="2PT FG%",
y_axis_label="3PT FG%",
)
# Draw with circle markers
pctFig.circle(
x="team2P%", y="team3P%", source=gm_stats_cds, size=12, color="black"
)
# Format the y-axis tick labels as percenages
pctFig.xaxis[0].formatter = NumeralTickFormatter(format="00.0%")
pctFig.yaxis[0].formatter = NumeralTickFormatter(format="00.0%")
# Create a figure relating the totals
totFig = figure(
title="Team Points vs Opponent Points, 2017-18 Regular Season",
plot_height=400,
plot_width=400,
tools=toolList,
x_axis_label="Team Points",
y_axis_label="Opponent Points",
)
# Draw with square markers
totFig.square(
x="teamPTS",
y="opptPTS",
source=gm_stats_cds,
size=10,
color=dict(field="winLoss", transform=win_loss_mapper),
)
# Create layout
grid = gridplot([[pctFig, totFig]])
# Visualize
show(grid)