@@ -1384,6 +1384,31 @@ def report():
1384
1384
1385
1385
return report
1386
1386
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 ()
1387
1412
1388
1413
def create_tree_map (frequency_dict , width , height ):
1389
1414
"""
@@ -1411,7 +1436,7 @@ def create_tree_map(frequency_dict, width, height):
1411
1436
fig .write_image (output_path )
1412
1437
fig .show ()
1413
1438
1414
- def __get_dates ():
1439
+ def __get_dates (df ):
1415
1440
"""
1416
1441
Get a dictionary that has keys as creation months and values as the number of datasets
1417
1442
@@ -1422,4 +1447,4 @@ def __get_dates():
1422
1447
df ['date' ] = pd .to_datetime (df ['creation_date' ], format = '%a %b %d %H:%M:%S %Y' )
1423
1448
df ['year_month' ] = df ['date' ].dt .strftime ('%B %Y' )
1424
1449
grouped_data = df ['year_month' ].value_counts ().to_dict ()
1425
- return grouped_data
1450
+ return grouped_data
0 commit comments