-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprinter.py
More file actions
26 lines (23 loc) · 802 Bytes
/
printer.py
File metadata and controls
26 lines (23 loc) · 802 Bytes
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
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from collections import defaultdict
def print_table(hashtag, sorttweets, top=10):
counts = defaultdict(int)
for x in sorttweets:
counts[x] += 1
stand = sorted(counts.items(), reverse=True, key=lambda tup: tup[1])[:top]
plt.style.use('classic')
df = pd.DataFrame(stand)
#fig, ax = plt.subplots()
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True
fig, ax = plt.subplots(1, 1)
plt.axis('off')
tab = ax.table(cellText=df.values, loc='center', colLabels = ('Naam', 'Aantal'))
tab.auto_set_font_size(False)
tab.set_fontsize(14)
fig.tight_layout()
#plt.show()
filename = f'{hashtag}_tweet_top10.png'
plt.savefig(filename)