-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_data_distribution.py
More file actions
68 lines (58 loc) · 1.87 KB
/
plot_data_distribution.py
File metadata and controls
68 lines (58 loc) · 1.87 KB
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 matplotlib.cm as cm
import seaborn as sns
import numpy as np
original_data = {
"English": [541.6],
"Finnish": [32.3],
"Code": [207.5],
"Eng-Fin": [8.0],
}
sampled_data = {
"English": [541.6],
"Finnish": [129.1],
"Code": [315.4],
"Eng-Fin": [8.0],
}
# Create a function to display the percentage and the original value
def autopct_format(values):
def my_format(pct):
total = sum(values)
val = int(round(pct*total/100.0))
return '{v:d}B ({p:.1f}%)'.format(p=pct,v=val)
return my_format
for data, name in ((original_data, 'original'), (sampled_data, 'sampled')):
# Create figure with specific size
fig, ax = plt.subplots(figsize=(12, 12))
# Variables to keep track of the cumulative size
total_size = sum([value[0] for value in data.values()])
labels = list(data.keys())
#colors = sns.color_palette("Set2")
colors = [
(0x91/256, 0xe5/256, 0x63/256),
(0x59/256, 0xaf/256, 0xff/256),
(0xd4/256, 0x70/256, 0xa4/256),
(0xf0/256, 0xa8/256, 0x57/256),
]
# Create the donut plot
wedges, texts, autotexts = ax.pie(
[value[0] for value in data.values()],
labels=labels,
colors=colors,
autopct=autopct_format([value[0] for value in data.values()]),
startangle=140,
pctdistance=0.75,
labeldistance=None,
wedgeprops=dict(width=0.5),
textprops={'fontsize': 34}
)
# Add a legend
# ax.legend(wedges, data.keys(),
# loc="center right",
# bbox_to_anchor=(0, 0.5),
# fontsize=15) # Increase the fontsize to make the legend bigger
# Equal aspect ratio ensures that pie is drawn as a circle
ax.axis('equal')
# Show the plot
plt.tight_layout()
plt.savefig(f"data_distribution_{name}.pdf")