44from collections import defaultdict
55from pathlib import Path
66
7- import matplotlib .colors as mcolors
87import matplotlib .pyplot as plt
98import numpy as np
109from tqdm import tqdm
1110
11+ from codeclash .analysis .viz .utils import FONT_BOLD , MODEL_TO_DISPLAY_NAME
1212from codeclash .constants import LOCAL_LOG_DIR
1313
1414
@@ -44,7 +44,7 @@ def main(log_dir: Path):
4444
4545 # Build matrix
4646 models = sorted ({m for pair in results .keys () for m in pair })
47- clean_names = [m .split ("/" )[- 1 ] for m in models ]
47+ clean_names = [MODEL_TO_DISPLAY_NAME [ m .split ("/" )[- 1 ] ] for m in models ]
4848 n = len (models )
4949
5050 matrix = np .full ((n , n ), np .nan )
@@ -54,26 +54,34 @@ def main(log_dir: Path):
5454 matrix [i , j ] = results [(m1 , m2 )][0 ] / results [(m1 , m2 )][1 ]
5555
5656 # Plot
57- fig , ax = plt . subplots ( figsize = ( 10 , 8 ) )
58- cmap = mcolors . LinearSegmentedColormap . from_list ( "br" , [ "#3498db" , "#ffffff" , "#e74c3c" ] )
59-
60- masked = np .ma .masked_where (np .isnan (matrix ), matrix )
61- im = ax .imshow (masked , cmap = cmap , vmin = 0 , vmax = 1 )
57+ FONT_BOLD . set_size ( 18 )
58+ _ , ax = plt . subplots ( figsize = ( 10 , 8 ) )
59+ # cmap = mcolors.LinearSegmentedColormap.from_list("br", ["#e74c3c", "#ffffff", "#3498db"])
60+ # masked = np.ma.masked_where(np.isnan(matrix), matrix)
61+ # im = ax.imshow(masked, cmap=cmap, vmin=0, vmax=1)
6262
6363 # Add percentages
6464 for i in range (n ):
6565 for j in range (n ):
6666 if not np .isnan (matrix [i , j ]):
6767 color = "white" if abs (matrix [i , j ] - 0.5 ) > 0.3 else "black"
68- ax .text (j , i , f"{ matrix [i , j ]:.0%} " , ha = "center" , va = "center" , color = color , fontweight = "bold" )
68+ ax .text (
69+ j ,
70+ i ,
71+ f"{ matrix [i , j ]:.0%} " ,
72+ ha = "center" ,
73+ va = "center" ,
74+ color = color ,
75+ fontweight = "bold" ,
76+ fontproperties = FONT_BOLD ,
77+ )
6978
7079 ax .set_xticks (range (n ))
7180 ax .set_yticks (range (n ))
72- ax .set_xticklabels (clean_names , rotation = 45 , ha = "right" )
73- ax .set_yticklabels (clean_names )
74- ax .set_title ("Model Win Rate Heatmap (Round Level)\n (Row beats Column)" , fontsize = 14 , fontweight = "bold" )
81+ ax .set_xticklabels (clean_names , rotation = 45 , ha = "right" , fontproperties = FONT_BOLD )
82+ ax .set_yticklabels (clean_names , fontproperties = FONT_BOLD )
7583
76- plt .colorbar (im , label = "Win Rate" )
84+ # plt.colorbar(im, label="Win Rate")
7785 plt .tight_layout ()
7886 plt .savefig ("heatmap_win_rates.png" , dpi = 300 , bbox_inches = "tight" )
7987 print ("Heatmap saved to heatmap_win_rates.png" )
0 commit comments