-
Notifications
You must be signed in to change notification settings - Fork 0
/
songFreq.py
52 lines (48 loc) · 2.07 KB
/
songFreq.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
##############################################################################
# _ _ __ _ _ _
# | | | | / _| | | | (_)
# | | __ _ ___| |_| |_ _ __ ___ | | | |_ ____
# | |/ _` / __| __| _| '_ ` _ \| | | | |_ /
# | | (_| \__ \ |_| | | | | | | \ \_/ / |/ /
# |_|\__,_|___/\__|_| |_| |_| |_|\___/|_/___|
#
# ----------------------------------------------------------------------------
# Artists frequencies routines
##############################################################################
import setup as stp
import pandas as pd
import matplotlib.pyplot as plt
from wordcloud import WordCloud
# %matplotlib inline
##############################################################################
# Aesthetics parameters
##############################################################################
(WIDTH, HEIGHT, RESOLUTION) = (3840, 2160, 500)
##############################################################################
# Read artists file
##############################################################################
data = pd.read_csv(stp.DATA_PATH + stp.USR + '_cln.csv', parse_dates=[3])
songs = sorted(data.get('Song').unique())
songCount = data.groupby('Song').size().sort_values(ascending=False)
##############################################################################
# Wordcloud
##############################################################################
wordcloudDef = WordCloud(
width=WIDTH, height=HEIGHT, max_words=2000,
relative_scaling=1, min_font_size=12,
background_color='Black', colormap='Purples',
font_path=stp.FONT
)
wordcloud = wordcloudDef.generate_from_frequencies(songCount)
ax1 = plt.axes(frameon=False)
plt.figure(figsize=(20, 20*(HEIGHT / WIDTH)), facecolor='k')
plt.imshow(wordcloud, interpolation='bilinear')
plt.tight_layout(pad=0)
plt.axis("off")
plt.savefig(
stp.IMG_PATH + '/SNG_WDC.png',
dpi=RESOLUTION, facecolor='k', edgecolor='w',
orientation='portrait', papertype=None, format=None,
transparent=False, bbox_inches=None, pad_inches='tight',
metadata=None
)