@@ -70,12 +70,9 @@ def __init__(self, df: pd.DataFrame):
7070 # Add hallucination category column
7171 self .df ["hal_cat1" ] = self .df .apply (self ._get_l_reason_breakdown , axis = 1 )
7272
73- # Sort models alphabetically by display name (reversed)
74- models = [m for m in df ["model_name" ].unique () if isinstance (m , str )]
75- model_display_pairs = [(m , MODEL_TO_DISPLAY_NAME .get (m , m )) for m in models ]
76- model_display_pairs .sort (key = lambda x : x [1 ].lower (), reverse = True )
77- self .models = [m for m , _ in model_display_pairs ]
78- self .display_names = [d for _ , d in model_display_pairs ]
73+ # Sort models alphabetically (reversed) - models are already display names
74+ models = sorted (df ["model_name" ].unique (), key = lambda x : x .lower (), reverse = True )
75+ self .models = models
7976 self .n_models = len (self .models )
8077
8178 # Create figure with 3 subplots sharing y-axis
@@ -123,14 +120,17 @@ def _add_stacked_bar_labels(self, ax, stacked_values: list[list[float]], min_val
123120 )
124121 left = left + np .array (values )
125122
126- def _add_total_bar_labels (self , ax , totals : list [float ], x_offset : float = 1 ):
123+ def _add_total_bar_labels (self , ax , totals : list [float ], x_offset_fraction : float = 0.02 ):
127124 """Add total value labels at the end of bars.
128125
129126 Args:
130127 ax: The matplotlib axis
131128 totals: List of total values for each bar
132- x_offset : Horizontal offset from the end of the bar
129+ x_offset_fraction : Horizontal offset as fraction of xlim span from the end of the bar
133130 """
131+ xlim = ax .get_xlim ()
132+ x_offset = (xlim [1 ] - xlim [0 ]) * x_offset_fraction
133+
134134 for i , total in enumerate (totals ):
135135 if total > 0 :
136136 font_total = FONT_BOLD .copy ()
@@ -218,7 +218,7 @@ def plot_grounding_analysis(self):
218218 ax .set_yticks (self .y_positions )
219219 font_ytick = FONT_REG .copy ()
220220 font_ytick .set_size (self .ytick_label_fontsize )
221- ax .set_yticklabels (self .display_names , fontproperties = font_ytick )
221+ ax .set_yticklabels (self .models , fontproperties = font_ytick )
222222
223223 # X-axis
224224 font_label = FONT_REG .copy ()
@@ -447,14 +447,35 @@ def main():
447447 df = pd .read_parquet (args .datafile )
448448
449449 # Process model name and filter
450- df ["model_name" ] = df ["model_name" ].str .split ("/" ).str [1 ]
451450 df = df .query ("model_name != opponent_model_name" ).copy ()
452451
453- # Create and save plot
452+ # Map model names to display names
453+ df ["model_name" ] = df ["model_name" ].map (lambda x : MODEL_TO_DISPLAY_NAME .get (x , x ))
454+
455+ # Extract game name from tournament_name
456+ df ["game_name" ] = df ["tournament_name" ].str .split ("." ).str [1 ]
457+
458+ # Get unique games
459+ games = sorted (df ["game_name" ].unique ())
460+
461+ # Create overall plot (all games combined)
454462 plotter = GroundingValidationPlotter (df )
455463 plotter .create_plot ()
456464 plotter .save (Path (args .output ))
457465
466+ # Create per-game plots
467+ output_path = Path (args .output )
468+ output_stem = output_path .stem
469+ output_dir = output_path .parent
470+
471+ for game_name in games :
472+ game_df = df [df ["game_name" ] == game_name ].copy ()
473+ game_output = output_dir / f"{ output_stem } _{ game_name } .pdf"
474+
475+ plotter = GroundingValidationPlotter (game_df )
476+ plotter .create_plot ()
477+ plotter .save (game_output )
478+
458479
459480if __name__ == "__main__" :
460481 main ()
0 commit comments