-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhistogram.py
78 lines (62 loc) · 2.27 KB
/
histogram.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
import matplotlib.pyplot as plt
import matplotlib.colors as colors
from matplotlib.colors import LogNorm
# Shows the distribution of the numbers of the given tipps. The goal is to
# see that all number are distributed equally or where the blacklist items
# have impact.
class HistogramBase:
# needs to be called before drawing to a new sub plot, see
# matplot doc for info
def newplot(self, idx, name):
plt.subplot(2, 1, idx, label=name)
def tipps(self, tipps):
self.newplot(1, 'Tipps')
self.tipps_do(tipps)
def tipps_do(self, tipps):
1
def skipped(self, skipped):
self.newplot(2, 'Skipped')
self.skipped_do(skipped)
def skipped_do(self, skipped):
1
def show(self):
plt.show()
class Histogram(HistogramBase):
def tipps_do(self, tipps):
numbers = []
for t in tipps:
numbers += t.numbers()
plt.hist(numbers, bins=49, color='tab:blue')
plt.title('Tipps')
def skipped_do(self, skipped):
numbers = []
for s in skipped:
numbers += s.tipp.numbers()
plt.hist(numbers, bins=49, color='tab:red')
plt.title('Skipped')
class Histogram2d(HistogramBase):
def __init__(self, nums, max_num, print_nums_per_line):
self.nums = nums
self.max_num = max_num
self.print_nums_per_line = print_nums_per_line
def _draw(self, name, tipps):
lines_count = int(self.max_num / self.print_nums_per_line)
plotdata = [[0. for x in range(self.print_nums_per_line)] for y in range(lines_count)]
for t in tipps:
coords = t.get_coords()
for coord in coords:
plotdata[coord[1]][coord[0]] += 1.
if len(tipps):
for i in range(lines_count):
for j in range(self.print_nums_per_line):
plotdata[i][j] = plotdata[i][j] / float(len(tipps)) * self.nums;
plt.pcolormesh(
plotdata,
norm=colors.Normalize())
plt.gca().invert_yaxis()
plt.colorbar()
plt.title(name)
def tipps_do(self, tipps):
self._draw('Tipps', tipps)
def skipped_do(self, skipped):
self._draw('Skipped', [s.tipp for s in skipped])