forked from sd17spring/InteractiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscaleline.py
More file actions
78 lines (68 loc) · 3.62 KB
/
Copy pathscaleline.py
File metadata and controls
78 lines (68 loc) · 3.62 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
71
72
73
74
75
76
77
78
'''
Authors: Vicky McDermott and Emily Lepert
This function represents the visual Scale Line object.
'''
from bokeh.plotting import figure
from bokeh.models import CategoricalColorMapper, ColumnDataSource
import bokeh.palettes
class ScaleLine:
def __init__(self):
'''
This initializes the ScaleLine class and assigns the x
coordinates, y coordinates, and color mapper. It also
sets up the initial probability, hover tool, and sets
up the figures and columndatasource for the scaleline.
'''
self.x_coords = [[0, 0, 10, 10], [10, 10, 20, 20], [20, 20, 30, 30],
[30, 30, 40, 40], [40, 40, 50, 50], [50, 50, 60, 60],
[60, 60, 70, 70], [70, 70, 80, 80], [80, 80, 90, 90],
[90, 90, 100, 100]]
self.y_coords = [[0, 1, 1, 0], [0, 1, 1, 0], [0, 1, 1, 0],
[0, 1, 1, 0], [0, 1, 1, 0], [0, 1, 1, 0],
[0, 1, 1, 0], [0, 1, 1, 0], [0, 1, 1, 0],
[0, 1, 1, 0]]
self.mapper = CategoricalColorMapper(factors=[0, 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],
palette=bokeh.palettes.
viridis(101))
self.figure = figure(title='Color Scale', plot_height=100, tools=[],
plot_width=700, x_axis_label='Probability')
def get_fig(self):
'''
Updates and returns the color scale line
for use in the layout
'''
self.update_scaleline()
return self.figure
def update_scaleline(self, probs=[10, 20, 30, 40, 50, 60, 70, 80, 90,
100]):
'''
Uses bokeh glyphs to draw the patches for the
color scale line
'''
self.source = ColumnDataSource(data={'x_coords': self.x_coords,
'y_coords': self.y_coords,
'probs': probs})
self.figure.patches(self.x_coords, self.y_coords, source=self.source,
color={'field': 'probs', 'transform': self.mapper})
if __name__ == '__main__':
scale_line = ScaleLine()