-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopulationbars.py
More file actions
51 lines (40 loc) · 1.18 KB
/
populationbars.py
File metadata and controls
51 lines (40 loc) · 1.18 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
import pickle
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
space = 'EDR'
method = 'density'
K = 12
min_samples = 2
eps = 1
gamma = 10**-8
if method == 'density':
prefix = 'eps'+str(eps)+'_minsamples'+str(min_samples)
elif method == 'spectral':
prefix = 'gamma'+str(gamma)+'_'+str(K)+'clusters'
elif method == 'hierarchical':
prefix = str(K)+'clusters'
else:
print('metric should be "density","hierarchical" or "spectral"')
exit()
with open('../data/populations/'+space+method+prefix+'.pickle','rb') as f:
populations = pickle.load(f)
if space=='ends' or space=='starts':
folder = 'termini'
prefix = prefix+space
else:
folder = space
noise = 8272-sum(populations)
idx = np.argsort(populations)[::-1]
pal = sns.color_palette('Paired',12)
plt.figure(figsize=(0.4,2))
plt.axis('off')
bottom=0
for i in range(len(populations)):
value = populations[idx[i]]
plt.bar(0,value,width=1,
bottom=bottom,
color=pal[idx[i]%12])
bottom += value
plt.bar(0,noise,width=1,bottom=bottom,color='0.8')
plt.savefig('../images/'+folder+'/'+method+'/'+prefix+'bar.png')