generated from heymynameiskai/template-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot.py
68 lines (57 loc) · 2 KB
/
plot.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
import matplotlib.pyplot as plt
import numpy as np
# labels = ['G1', 'G2', 'Gnfkdlsnfjakdnkl3', 'G4', 'G5']
# online = np.array((100, 35, 30, 35, 27))
# video = np.array((30, 35, 30, 35, 27))
# audio = np.array((5, 35, 30, 35, 27))
#
# width = 0.5 # the width of the bars: can also be len(x) sequence
#
# fig, ax = plt.subplots()
#
# ax.bar(labels, online, width, label='Online', color='#0099ff')
# ax.bar(labels, video, width, bottom=online, label='Video', color='#33cc33')
# ax.bar(labels, audio, width, bottom=online+video, label='Audio', color='#ff9900')
#
# plt.xticks(rotation=90)
#
#
# ax.set_ylabel('Aufrufe')
# ax.set_title('Aufrufe nach Video und Format')
# ax.legend()
#
# plt.savefig('plot.pdf', format='pdf')
def plot(playlist_id, statistics):
# labels = []
labels = []
online = []
video = []
audio = []
online_video_sum = []
for k in sorted(statistics.keys()):
# reorder hits for mathplot
labels.append(statistics[k]['title'])
online.append(int(statistics[k]['hits_online']))
video.append(int(statistics[k]['hits_video']))
audio.append(int(statistics[k]['hits_audio']))
online_video_sum.append(int(statistics[k]['hits_online']) + int(statistics[k]['hits_video']))
# plot
# fig, ax = plt.subplots()
(fig, ax) = plt.subplots(figsize=(10, 7))
ax.bar(labels, online, label='Online', color='#0099ff')
ax.bar(labels, video, bottom=online, label='Video', color='#33cc33')
ax.bar(labels, audio, bottom=online_video_sum, label='Audio', color='#ff9900')
ax.set_ylabel('Aufrufe')
ax.set_title('Aufrufe nach Video und Format')
ax.legend()
plt.subplots_adjust(bottom=0.5)
plt.xticks(rotation=90, fontsize=8)
# # TODO
# length = len(statistics)
# stop = length - length*0.07 + 0.7
#
# print(length, stop)
#
# plt.xlim(-0.5, stop) # this removes the gap between the bars and the y-axis
plt.savefig('export_pdf/tmp/'+playlist_id+'.png', format='png', dpi=300)
plt.close('all')