/
__init__.py
208 lines (172 loc) · 8.13 KB
/
__init__.py
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
from __future__ import absolute_import
import numpy as np
from bokeh.palettes import all_palettes
from ...core import (Store, Overlay, NdOverlay, Layout, AdjointLayout,
GridSpace, GridMatrix, NdLayout, config)
from ...element import (Curve, Points, Scatter, Image, Raster, Path,
RGB, Histogram, Spread, HeatMap, Contours, Bars,
Box, Bounds, Ellipse, Polygons, BoxWhisker, Arrow,
ErrorBars, Text, HLine, VLine, Spline, Spikes,
Table, ItemTable, Area, HSV, QuadMesh, VectorField,
Graph, Nodes, EdgePaths)
from ...core.options import Options, Cycle, Palette
try:
from ...interface import DFrame
except:
DFrame = None
from .annotation import TextPlot, LineAnnotationPlot, SplinePlot, ArrowPlot
from .callbacks import Callback # noqa (API import)
from .element import OverlayPlot, ElementPlot
from .chart import (PointPlot, CurvePlot, SpreadPlot, ErrorPlot, HistogramPlot,
SideHistogramPlot, BarPlot, SpikesPlot, SideSpikesPlot,
AreaPlot, VectorFieldPlot, BoxWhiskerPlot)
from .graphs import GraphPlot
from .path import PathPlot, PolygonPlot, ContourPlot
from .plot import GridPlot, LayoutPlot, AdjointLayoutPlot
from .raster import RasterPlot, RGBPlot, HeatMapPlot, HSVPlot, QuadMeshPlot
from .renderer import BokehRenderer
from .tabular import TablePlot
from .util import bokeh_version
Store.renderers['bokeh'] = BokehRenderer.instance()
if len(Store.renderers) == 1:
Store.current_backend = 'bokeh'
associations = {Overlay: OverlayPlot,
NdOverlay: OverlayPlot,
GridSpace: GridPlot,
GridMatrix: GridPlot,
AdjointLayout: AdjointLayoutPlot,
Layout: LayoutPlot,
NdLayout: LayoutPlot,
# Charts
Curve: CurvePlot,
Bars: BarPlot,
BoxWhisker: BoxWhiskerPlot,
Points: PointPlot,
Scatter: PointPlot,
ErrorBars: ErrorPlot,
Spread: SpreadPlot,
Spikes: SpikesPlot,
Area: AreaPlot,
VectorField: VectorFieldPlot,
Histogram: HistogramPlot,
# Rasters
Image: RasterPlot,
RGB: RGBPlot,
HSV: HSVPlot,
Raster: RasterPlot,
HeatMap: HeatMapPlot,
QuadMesh: QuadMeshPlot,
# Paths
Path: PathPlot,
Contours: ContourPlot,
Path: PathPlot,
Box: PathPlot,
Bounds: PathPlot,
Ellipse: PathPlot,
Polygons: PolygonPlot,
# Annotations
HLine: LineAnnotationPlot,
VLine: LineAnnotationPlot,
Text: TextPlot,
Spline: SplinePlot,
Arrow: ArrowPlot,
# Graph Elements
Graph: GraphPlot,
Nodes: PointPlot,
EdgePaths: PathPlot,
# Tabular
Table: TablePlot,
ItemTable: TablePlot}
if DFrame is not None:
associations[DFrame] = TablePlot
Store.register(associations, 'bokeh')
if config.style_17:
ElementPlot.show_grid = True
RasterPlot.show_grid = True
ElementPlot.show_frame = True
else:
# Raster types, Path types and VectorField should have frames
for framedcls in [VectorFieldPlot, ContourPlot, PathPlot, PolygonPlot,
RasterPlot, RGBPlot, HSVPlot, QuadMeshPlot, HeatMapPlot]:
framedcls.show_frame = True
AdjointLayoutPlot.registry[Histogram] = SideHistogramPlot
AdjointLayoutPlot.registry[Spikes] = SideSpikesPlot
point_size = np.sqrt(6) # Matches matplotlib default
Cycle.default_cycles['default_colors'] = ['#30a2da', '#fc4f30', '#e5ae38',
'#6d904f', '#8b8b8b']
# Register bokeh.palettes with Palette and Cycle
def colormap_generator(palette):
return lambda value: palette[int(value*(len(palette)-1))]
Palette.colormaps.update({name: colormap_generator(p[max(p.keys())])
for name, p in all_palettes.items()})
Cycle.default_cycles.update({name: p[max(p.keys())] for name, p in all_palettes.items()
if max(p.keys()) < 256})
dflt_cmap = 'hot' if config.style_17 else 'fire'
options = Store.options(backend='bokeh')
# Charts
options.Curve = Options('style', color=Cycle(), line_width=2)
options.BoxWhisker = Options('style', box_fill_color=Cycle(), whisker_color='black',
box_line_color='black', outlier_color='black')
options.Scatter = Options('style', color=Cycle(), size=point_size, cmap=dflt_cmap)
options.Points = Options('style', color=Cycle(), size=point_size, cmap=dflt_cmap)
if not config.style_17:
options.Points = Options('plot', show_frame=True)
options.Histogram = Options('style', line_color='black', fill_color=Cycle())
options.ErrorBars = Options('style', color='black')
options.Spread = Options('style', color=Cycle(), alpha=0.6, line_color='black')
options.Bars = Options('style', color=Cycle(), line_color='black', width=0.8)
options.Spikes = Options('style', color='black', cmap='fire')
options.Area = Options('style', color=Cycle(), alpha=1, line_color='black')
options.VectorField = Options('style', color='black')
# Paths
options.Contours = Options('style', color=Cycle())
if not config.style_17:
options.Contours = Options('plot', show_legend=True)
options.Path = Options('style', color=Cycle())
options.Box = Options('style', color='black')
options.Bounds = Options('style', color='black')
options.Ellipse = Options('style', color='black')
options.Polygons = Options('style', color=Cycle(), line_color='black')
# Rasters
options.Image = Options('style', cmap=dflt_cmap)
options.GridImage = Options('style', cmap=dflt_cmap)
options.Raster = Options('style', cmap=dflt_cmap)
options.QuadMesh = Options('style', cmap=dflt_cmap, line_alpha=0)
options.HeatMap = Options('style', cmap='RdYlBu_r', line_alpha=0)
# Annotations
options.HLine = Options('style', color=Cycle(), line_width=3, alpha=1)
options.VLine = Options('style', color=Cycle(), line_width=3, alpha=1)
options.Arrow = Options('style', arrow_size=10)
# Graphs
options.Graph = Options('style', node_size=20, node_fill_color=Cycle(),
node_line_color='black',
node_selection_fill_color='limegreen',
node_nonselection_fill_color=Cycle(),
node_hover_line_color='black',
node_hover_fill_color='indianred',
node_nonselection_alpha=0.2,
edge_nonselection_alpha=0.2,
edge_line_color='black', edge_line_width=2,
edge_nonselection_line_color='black',
edge_hover_line_color='indianred',
edge_selection_line_color='limegreen')
options.Nodes = Options('style', line_color='black', color=Cycle(),
size=20, nonselection_fill_color=Cycle(),
selection_fill_color='limegreen',
hover_fill_color='indianred')
options.Nodes = Options('plot', tools=['hover', 'tap'])
options.EdgePaths = Options('style', color='black', nonselection_alpha=0.2,
line_width=2, selection_color='limegreen',
hover_line_color='indianred')
options.EdgePaths = Options('plot', tools=['hover', 'tap'])
# Define composite defaults
options.GridMatrix = Options('plot', shared_xaxis=True, shared_yaxis=True,
xaxis=None, yaxis=None)
if bokeh_version >= '0.12.5':
options.Overlay = Options('style', click_policy='mute')
options.NdOverlay = Options('style', click_policy='mute')
options.Curve = Options('style', muted_alpha=0.2)
options.Path = Options('style', muted_alpha=0.2)
options.Scatter = Options('style', muted_alpha=0.2)
options.Points = Options('style', muted_alpha=0.2)
options.Polygons = Options('style', muted_alpha=0.2)