File size: 891 Bytes
f74da72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Plots a pie-chart showing an overview of the genre distribution in the dataset
"""

import csv
import random

import matplotlib.pyplot as plt
import seaborn as sns

# Go through metadata CSV and read genre attribute
with open("../JamendoLyrics.csv", "r") as f:
    rows = csv.DictReader(f)
    genres = [row["Genre"] for row in rows]
    unique_genres = list(set(genres))
    genre_freq = [len([g for g in genres if g == target]) for target in unique_genres]

# define Seaborn color palette to use
colors = sns.color_palette("Set3")
random.shuffle(colors)

plt.rcParams["font.family"] = "serif"
plt.rcParams["font.serif"] = ["Times New Roman"]
plt.rcParams["font.size"] = 14

# Create pie chart
plt.pie(
    genre_freq,
    labels=unique_genres,
    radius=1,
    wedgeprops=dict(width=0.3, edgecolor="w"),
    colors=colors,
)
plt.savefig("genre_distribution.pdf", bbox_inches="tight")