@@ -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
13881413def create_tree_map (frequency_dict , width , height ):
13891414 """
@@ -1409,4 +1434,4 @@ def create_tree_map(frequency_dict, width, height):
14091434 today = date .today ()
14101435 output_path = f'treemap-{ today .strftime ("%Y%m%d" )} .png'
14111436 fig .write_image (output_path )
1412- fig .show ()
1437+ fig .show ()
0 commit comments