-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplotter.py
152 lines (109 loc) · 3.17 KB
/
plotter.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
#!/usr/bin/python3
# type: ignore
# %%
import matplotlib.pyplot as m
import numpy as np
import detective
from util import collection, taxonomy
from util.common import flatten, tree_size
from util.database import database
from util.plotting import BubbleChart
m.rcParams['figure.dpi'] = 175
def packed_bubble(names, counts, spacing=5):
"""plot"""
chart = BubbleChart(area=counts, bubble_spacing=spacing)
chart.collapse()
_, ax = m.subplots(subplot_kw=dict(aspect='equal'))
prop_cycle = m.rcParams['axes.prop_cycle']
colors = prop_cycle.by_key()['color'] * 50
chart.plot(ax, names, colors)
ax.axis('off')
ax.relim()
ax.autoscale_view()
m.show()
# %%
# similiarity distances between all subjects
print('loading... ', end='', flush=True)
ns, ts, ss, _ = detective.table_builder(False)
print('done')
def scatterer():
_, ax = m.subplots()
for i, name in enumerate(ns):
size = len(ss[i])
x = [i for _ in range(size)]
y = ss[i]
s = [1 for _ in range(size)]
ax.scatter(x, y, s=s)
m.title('Distances between subjects')
m.xlabel('Distance')
m.ylabel('Occurrences')
m.hist(flatten(ss), bins=20)
m.show()
# %%
# cache prefetch timing
db = database
choices = db.keys('diving', 'cache-speed')
when = choices[0]
times = db.get('diving', 'cache-speed', when, default=[])
times = [float(t) for t in times]
m.title('Digital Ocean CDN Prefetch Timing')
percentiles = [0.01, 0.1, 1, 25, 50, 75, 99, 99.9, 99.99]
m.bar([str(p) for p in percentiles], np.percentile(times, percentiles))
# m.plot(times)
m.ylabel('Seconds')
m.xlabel('Percentile')
m.grid(True)
m.show()
# %%
# common names bar graph
tree = collection.build_image_tree() # common names
sizes = {k: tree_size(v) for k, v in tree.items()}
for k, v in list(sizes.items()):
if v > 50:
continue
sizes.setdefault('other', 0)
sizes['other'] += v
del sizes[k]
names, counts = list(zip(*sorted(sizes.items())))
xs = [i for i in range(len(counts))]
m.bar(xs, counts)
m.title('Diving Pictures')
m.ylabel('Pictures')
m.xticks(xs, names, rotation=45, ha='right')
m.show()
# %%
# common names packed bubble chart
m.rcParams.update({'font.size': 6})
tree = collection.build_image_tree() # common names
tree = tree['shrimp']
sizes = {k: tree_size(v) for k, v in tree.items()}
filter = 1
for k, v in list(sizes.items()):
if v > filter:
continue
sizes.setdefault('other', 0)
sizes['other'] += v
del sizes[k]
sizes = {k.title().replace(' ', '\n') + f'\n{v}': 2 * v for k, v in sizes.items()}
names, counts = list(zip(*sizes.items()))
packed_bubble(names, counts, 1)
# %%
# animalia packed bubble chart
m.rcParams.update({'font.size': 7})
tree = taxonomy.gallery_tree()
tree = tree['Animalia']['Chordata']['Actinopterygii']['Perciformes']
sizes = {k: tree_size(v) for k, v in tree.items()}
filter = 5
to_drop = []
other = 0
for k, v in sizes.items():
if v > filter:
continue
other += v
to_drop.append(k)
if other:
sizes['other'] = other
sizes = {f'{k.title().split(" ")[0]}\n{v}': 2 * v for k, v in sizes.items() if k not in to_drop}
names, counts = list(zip(*sizes.items()))
packed_bubble(names, counts, 1)
# %%