Skip to content

Commit 6099331

Browse files
authored
Merge pull request #62 from brain-image-library/61-general-modality-tree-map
General Modality Tree Map: Update
2 parents 7c386ab + f028e28 commit 6099331

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
@@ -30,6 +30,44 @@ def get_random_sample(df):
3030

3131
return result.json()
3232

33+
import urllib.request
34+
import matplotlib.pyplot as plt
35+
import seaborn as sb
36+
import squarify
37+
38+
def __get_lable_dict(name_lst):
39+
"""
40+
input: a list of University names
41+
output: a dictionary with the names as keys and abbreviations that include the first letter of each University name
42+
"""
43+
return {uni_name: ''.join(word[0].upper() for word in uni_name.split()) for uni_name in name_lst}
44+
45+
46+
def __get_general_modality_treemap(df):
47+
"""
48+
input: dataframe
49+
output: tree map that displays the frequencies of "generalmodality" that occur in dataframe
50+
"""
51+
modality_counts = df['generalmodality'].value_counts().to_dict()
52+
53+
plt.figure(figsize=(14,10))
54+
values = list(modality_counts.values())
55+
name = list(modality_counts.keys())
56+
abbrName = __get_lable_dict(name)
57+
colors = sb.color_palette("ocean", len(values))
58+
59+
num_labels = len(df.keys())
60+
print(num_labels)
61+
62+
ax = squarify.plot(sizes=values, color=colors, label=abbrName.values(), alpha=0.8)
63+
ax.axis('off')
64+
ax.invert_xaxis()
65+
ax.set_aspect('equal')
66+
67+
legend_patches = [plt.Rectangle((0, 0), 1, 1, fc=color) for color in colors]
68+
plt.legend(legend_patches, name, loc='upper left', bbox_to_anchor=(1, 1), fontsize='medium')\
69+
70+
plt.show()
3371

3472
def today():
3573
"""

0 commit comments

Comments
 (0)