Skip to content

Commit 84f48d7

Browse files
authored
Merge pull request #66 from brain-image-library/58-treemap-of-projects-frequency
58 treemap of projects frequency
2 parents 8f72097 + bef2872 commit 84f48d7

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

braininventory/get.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import pandas as pd
33
import json
44
from datetime import date
5+
import squarify
6+
import matplotlib.pyplot as plt
57

68

79
def today():
@@ -54,26 +56,30 @@ def __get_contributor(df):
5456
def __get_affilation(df):
5557
return df["affiliation"].value_counts().to_dict()
5658

59+
5760
def __get_awards(df):
5861
return df["award_number"].unique()
5962

6063

6164
def __get_award_number(df):
6265
return df["award_number"].value_counts().to_dict()
6366

67+
6468
def __get_species(df):
6569
return df["species"].value_counts().to_dict()
6670

6771

6872
def __get_cnbtaxonomy(df):
6973
return df["cnbtaxonomy"].value_counts().to_dict()
7074

75+
7176
def __get_genotypes(df):
7277
"""
7378
Write documentation here.
7479
"""
7580
return df["genotype"].unique()
7681

82+
7783
def __get_genotype_frequency(df):
7884
"""
7985
Write documentation here.
@@ -84,6 +90,7 @@ def __get_genotype_frequency(df):
8490
def __get_generalmodality(df):
8591
return df["generalmodality"].value_counts().to_dict()
8692

93+
8794
def __get_techniques(df):
8895
"""
8996
Write documentation here.
@@ -97,9 +104,11 @@ def techniques_frequency(df):
97104
"""
98105
return df["technique"].value_counts().to_dict()
99106

107+
100108
def __get_locations(df):
101109
return df["locations"].value_counts().to_dict()
102110

111+
103112
def __get_contributors(df):
104113
"""
105114
This returns an array of contributor names from the contributorname column.
@@ -128,6 +137,24 @@ def __get_number_of_projects(df):
128137

129138
return len(df["project"].unique())
130139

140+
141+
def get_projects_treemap(df):
142+
"""
143+
Created a code for the visualization of projects frequency
144+
145+
Input: project values
146+
Output: treemap graph of projects frequency
147+
"""
148+
149+
df = df["project"].value_counts().to_dict()
150+
sizes_list = list(df.values())
151+
names_list = list(df.keys())
152+
squarify.plot(sizes_list)
153+
154+
filename = f'treemap-projects-{datetime.now().strftime("%Y%m%d")}.png'
155+
plt.savefig("path/to/save/plot.png")
156+
157+
131158
def report():
132159
# Get today's date
133160
tdate = date.today()
@@ -153,4 +180,7 @@ def report():
153180
report["technique"] = __get_technique(df)
154181
report["locations"] = __get_locations(df)
155182

183+
# plots
184+
get_projects_treemap(df)
185+
156186
return report

0 commit comments

Comments
 (0)