Skip to content

Commit f028e28

Browse files
authored
General Modality Tree Map update
1 parent 8f72097 commit f028e28

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

braininventory/get.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,44 @@
33
import json
44
from datetime import date
55

6+
import urllib.request
7+
import matplotlib.pyplot as plt
8+
import seaborn as sb
9+
import squarify
10+
11+
def __get_lable_dict(name_lst):
12+
"""
13+
input: a list of University names
14+
output: a dictionary with the names as keys and abbreviations that include the first letter of each University name
15+
"""
16+
return {uni_name: ''.join(word[0].upper() for word in uni_name.split()) for uni_name in name_lst}
17+
18+
19+
def __get_general_modality_treemap(df):
20+
"""
21+
input: dataframe
22+
output: tree map that displays the frequencies of "generalmodality" that occur in dataframe
23+
"""
24+
modality_counts = df['generalmodality'].value_counts().to_dict()
25+
26+
plt.figure(figsize=(14,10))
27+
values = list(modality_counts.values())
28+
name = list(modality_counts.keys())
29+
abbrName = __get_lable_dict(name)
30+
colors = sb.color_palette("ocean", len(values))
31+
32+
num_labels = len(df.keys())
33+
print(num_labels)
34+
35+
ax = squarify.plot(sizes=values, color=colors, label=abbrName.values(), alpha=0.8)
36+
ax.axis('off')
37+
ax.invert_xaxis()
38+
ax.set_aspect('equal')
39+
40+
legend_patches = [plt.Rectangle((0, 0), 1, 1, fc=color) for color in colors]
41+
plt.legend(legend_patches, name, loc='upper left', bbox_to_anchor=(1, 1), fontsize='medium')\
42+
43+
plt.show()
644

745
def today():
846
"""

0 commit comments

Comments
 (0)