1313from codeclash .constants import LOCAL_LOG_DIR
1414
1515
16- def main (log_dir : Path , unit : str = "rounds" , output_file : Path = ASSETS_DIR / "heatmap_win_rates.png " ):
16+ def main (log_dir : Path , unit : str = "rounds" , output_file : Path = ASSETS_DIR / "heatmap_win_rates.pdf " ):
1717 print (f"Creating win rate heatmap from logs in { log_dir } ..." )
1818
1919 # Track round-level wins: (model1, model2) -> [wins, total_rounds]
@@ -71,35 +71,37 @@ def main(log_dir: Path, unit: str = "rounds", output_file: Path = ASSETS_DIR / "
7171 # Plot
7272 FONT_BOLD .set_size (18 )
7373 _ , ax = plt .subplots (figsize = (10 , 8 ))
74- cmap = mcolors .LinearSegmentedColormap .from_list ("br" , ["#e74c3c" , "#ffffff" , "#3498db" ])
74+ cmap = mcolors .LinearSegmentedColormap .from_list ("rg" , ["#f44336" , "#ffffff" , "#4caf50" ]) # Red-Green
75+
7576 masked = np .ma .masked_where (np .isnan (matrix ), matrix )
7677 ax .imshow (masked , cmap = cmap , vmin = 0 , vmax = 1 )
7778
7879 # Add percentages
7980 for i in range (n ):
8081 for j in range (n ):
8182 if not np .isnan (matrix [i , j ]):
82- color = "white" if abs (matrix [i , j ] - 0.5 ) > 0.3 else "black"
8383 ax .text (
8484 j ,
8585 i ,
8686 f"{ matrix [i , j ]:.0%} " ,
8787 ha = "center" ,
8888 va = "center" ,
89- color = color ,
89+ color = "black" ,
9090 fontweight = "bold" ,
9191 fontproperties = FONT_BOLD ,
92+ fontsize = FONT_BOLD .get_size () + 2 ,
9293 )
9394
9495 ax .set_xticks (range (n ))
9596 ax .set_yticks (range (n ))
9697 ax .set_xticklabels (clean_names , rotation = 45 , ha = "right" , fontproperties = FONT_BOLD )
9798 ax .set_yticklabels (clean_names , fontproperties = FONT_BOLD )
99+ ax .tick_params (length = 0 )
98100
99101 # plt.colorbar(im, label="Win Rate")
100102 plt .tight_layout ()
101103 if unit == "tournaments" :
102- suffix = output_file .suffix or ".png "
104+ suffix = output_file .suffix or ".pdf "
103105 output_file = output_file .with_name (f"{ output_file .stem } _tournaments{ suffix } " )
104106 plt .savefig (output_file , dpi = 300 , bbox_inches = "tight" )
105107 print (f"Heatmap saved to { output_file } " )
@@ -110,7 +112,7 @@ def main(log_dir: Path, unit: str = "rounds", output_file: Path = ASSETS_DIR / "
110112 parser .add_argument ("-d" , "--log_dir" , type = Path , default = LOCAL_LOG_DIR , help = "Path to logs" )
111113 parser .add_argument ("-u" , "--unit" , type = str , default = "rounds" , help = "Unit of analysis: rounds or tournaments" )
112114 parser .add_argument (
113- "-o" , "--output_file" , type = Path , default = ASSETS_DIR / "heatmap_win_rates.png " , help = "Output file path"
115+ "-o" , "--output_file" , type = Path , default = ASSETS_DIR / "heatmap_win_rates.pdf " , help = "Output file path"
114116 )
115117 args = parser .parse_args ()
116118 main (** vars (args ))
0 commit comments