Skip to content

Commit 105a3a2

Browse files
authored
Merge branch 'main' into 96-dictionary-of-creation-months-and-numbers
2 parents 1696d98 + b51382a commit 105a3a2

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

braininventory/get.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,6 +1384,31 @@ def report():
13841384

13851385
return report
13861386

1387+
def create_general_modality_plot(df):
1388+
# Creates a segmented bar graph that shows the proportion of general modalities over the years.
1389+
# Dropped the null values (no creation dates)
1390+
df[~df['creation_date'].isnull()]
1391+
df['dates'] = pd.to_datetime(df['creation_date'])
1392+
df['year'] = df['dates'].dt.year
1393+
df = df.dropna(subset=['year'])
1394+
df['year'] = df['year'].astype(int)
1395+
grouped = df.groupby(df['dates'].dt.year)
1396+
1397+
import matplotlib.pyplot as plt
1398+
1399+
grouped = df.groupby(['year', 'generalmodality']).size().reset_index(name='count')
1400+
1401+
pivot_df = grouped.pivot(index='year', columns='generalmodality', values='count').fillna(0)
1402+
1403+
pivot_df.plot(kind='bar', stacked=True)
1404+
1405+
plt.title('General Modalities')
1406+
plt.ylabel('Number of Datasets')
1407+
plt.xlabel('Year')
1408+
plt.xticks(rotation=45)
1409+
plt.tight_layout()
1410+
1411+
plt.show()
13871412

13881413
def create_tree_map(frequency_dict, width, height):
13891414
"""
@@ -1411,7 +1436,7 @@ def create_tree_map(frequency_dict, width, height):
14111436
fig.write_image(output_path)
14121437
fig.show()
14131438

1414-
def __get_dates():
1439+
def __get_dates(df):
14151440
"""
14161441
Get a dictionary that has keys as creation months and values as the number of datasets
14171442
@@ -1422,4 +1447,4 @@ def __get_dates():
14221447
df['date'] = pd.to_datetime(df['creation_date'], format='%a %b %d %H:%M:%S %Y')
14231448
df['year_month'] = df['date'].dt.strftime('%B %Y')
14241449
grouped_data = df['year_month'].value_counts().to_dict()
1425-
return grouped_data
1450+
return grouped_data

0 commit comments

Comments
 (0)