@@ -252,6 +252,45 @@ def plot_shiny(
252252
253253 return ax
254254
255+ def plot_category (
256+ self ,
257+ impact_func_creator : Callable [..., ImpactFuncSet ],
258+ haz_type ,
259+ impf_id ,
260+ input = None ,
261+ category = None ,
262+ category_col_dict = None ,
263+ ** impf_set_plot_kwargs
264+ ):
265+
266+ """Plot all impact functions with appropriate color coding according to a category"""
267+ impf_set_arr = np .array (self ._to_impf_sets (impact_func_creator ))
268+
269+ if category_col_dict is None :
270+ unique_categories = self .data [("Event" , category )].unique ()
271+ print (unique_categories )
272+ unique_colors = plt .get_cmap ("Set1" )(np .linspace (0 , 1 , len (unique_categories )))
273+ else :
274+ unique_categories = list (category_col_dict .keys ())
275+ unique_colors = list (category_col_dict .values ())
276+
277+ fig ,ax = plt .subplots ()
278+ for sel_category ,color in zip (unique_categories ,unique_colors ):
279+ cat_idx = self .data [("Event" , category )] == sel_category
280+
281+ for i ,impf_set in enumerate (impf_set_arr [cat_idx ]):
282+ impf = impf_set .get_func (haz_type = haz_type , fun_id = impf_id )
283+ label = f"{ sel_category } , n={ cat_idx .sum ()} " if i == 0 else None
284+ ax .plot (impf .intensity , impf .paa * impf .mdd , ** impf_set_plot_kwargs ,
285+ color = color ,label = label )
286+ # impf.mdr.plot(axis=ax, **impf_set_plot_kwargs)#, label=sel_category)
287+
288+ ax .legend (title = category ,bbox_to_anchor = (1.05 , 1 ),loc = 'upper left' ,frameon = False )
289+ # Cosmetics
290+ ax .set_xlabel (f"Intensity [{ impf .intensity_unit } ]" )
291+ ax .set_ylabel ("Impact" )
292+ return ax
293+
255294
256295@dataclass
257296class EnsembleOptimizer (ABC ):
0 commit comments