| |
| import pandas as pd |
| import matplotlib.pyplot as plt |
| import numpy as np |
| from pathlib import Path |
| from matplotlib.colors import LinearSegmentedColormap |
| from matplotlib.ticker import FuncFormatter |
|
|
| |
| plt.rcParams["font.family"] = "Times New Roman" |
|
|
|
|
| def plot_llm_share_heatmap(): |
| base_dir = Path(__file__).parent |
| csv_file = base_dir / "llm_share_summary.csv" |
|
|
| df = pd.read_csv(csv_file, index_col=0) |
|
|
| series_info = [ |
| ("Email Responder", 2), |
| ("Recruitment", 3), |
| ("Markdown Val.", 2), |
| ("Game Builder", 2), |
| ("SQL Asst.", 3), |
| ("Landing Pg.", 3), |
| ("Book Writer", 3), |
| ("Social M. M.", 3), |
| ] |
|
|
| |
| desired_suffix_order = ["CrewAI", "MCP", "A2A", "A2A_mix"] |
| suffix_display = { |
| "CrewAI": "CrewAI", |
| "MCP": "MCP", |
| "A2A": "A2A", |
| "A2A_mix": "H-A2A", |
| } |
|
|
| new_columns = [] |
| suffixes = [] |
| for series_name, _ in series_info: |
| for suf in desired_suffix_order: |
| col_name = f"{series_name} ({suf})" |
| if col_name in df.columns: |
| new_columns.append(col_name) |
| suffixes.append(suffix_display[suf]) |
|
|
| if new_columns: |
| df = df[new_columns] |
|
|
| fig, ax = plt.subplots(figsize=(18, 5.2)) |
|
|
| colors = ["#d73027", "#fee08b", "#d9ef8b", "#66bd63", "#1a9850"] |
| n_bins = 100 |
| cmap = LinearSegmentedColormap.from_list("custom", colors, N=n_bins) |
|
|
| im = ax.imshow(df.values, cmap=cmap, aspect="auto", vmin=0.85, vmax=1.0) |
|
|
| ax.set_xticks(np.arange(len(df.columns))) |
| ax.set_yticks(np.arange(len(df.index))) |
| ax.set_xticklabels( |
| suffixes, rotation=0, ha="center", fontsize=12, fontweight="bold" |
| ) |
|
|
| y_labels = [] |
| for label in df.index: |
| if "Gemini-2.5-flash-nothinking" in label: |
| y_labels.append("Gemini-2.5\n-flash\n-nothinking") |
| elif "Gemini-2.5-flash" in label: |
| y_labels.append("Gemini-2.5\n-flash") |
| elif "DeepSeek-V3" in label: |
| y_labels.append("DeepSeek\n-V3") |
| elif "DeepSeek-R1" in label: |
| y_labels.append("DeepSeek\n-R1") |
| elif "GPT-4o-mini" in label: |
| y_labels.append("GPT-4o\n-mini") |
| elif "Qwen3-235b" in label: |
| y_labels.append("Qwen3\n-235b") |
| elif "Overall" in label: |
| y_labels.append("Overall\nAverage") |
| else: |
| y_labels.append(label) |
| ax.set_yticklabels(y_labels, fontsize=12, fontweight="bold") |
|
|
| for i in range(len(df.index)): |
| for j in range(len(df.columns)): |
| value = df.iloc[i, j] |
| if pd.notna(value): |
| text_color = "white" if value < 0.92 else "black" |
| display_pct = round(value * 100, 2) |
| if display_pct >= 100.0: |
| display_pct = 99.99 |
| text = ax.text( |
| j, |
| i, |
| f"{display_pct:.2f}", |
| ha="center", |
| va="center", |
| color=text_color, |
| fontsize=15, |
| fontweight="bold", |
| ) |
|
|
| cbar = fig.colorbar(im, ax=ax, fraction=0.03, pad=0.01) |
| cbar.ax.tick_params(labelsize=13) |
| for label in cbar.ax.get_yticklabels(): |
| label.set_fontweight("bold") |
| cbar.ax.yaxis.set_major_formatter(FuncFormatter(lambda x, pos: f"{x * 100:.2f}%")) |
| cbar.set_label("") |
|
|
| ax.spines["top"].set_visible(False) |
| ax.spines["right"].set_visible(False) |
| ax.spines["bottom"].set_visible(False) |
| ax.spines["left"].set_visible(False) |
|
|
| ax.set_xticks(np.arange(len(df.columns) + 1) - 0.5, minor=True) |
| ax.set_yticks(np.arange(len(df.index) + 1) - 0.5, minor=True) |
| ax.grid(which="minor", color="gray", linestyle="-", linewidth=0.5) |
| ax.tick_params(which="minor", size=0) |
|
|
| |
| cum_pos = 0 |
| for series_name, count in series_info: |
| center_pos = cum_pos + (count - 1) / 2 |
| ax.text( |
| center_pos, |
| len(df.index) + 0.18, |
| series_name, |
| ha="center", |
| va="top", |
| fontsize=12, |
| fontweight="bold", |
| ) |
|
|
| if cum_pos > 0: |
| ax.axvline(x=cum_pos - 0.5, color="black", linewidth=2, linestyle="-") |
|
|
| cum_pos += count |
|
|
| |
| plt.subplots_adjust(bottom=0.1, top=0.97, left=0.08, right=0.96) |
|
|
| output_file = base_dir / "llm_share_heatmap.pdf" |
| plt.savefig(output_file, dpi=300, bbox_inches="tight") |
| print(f"Heatmap saved to: {output_file}") |
|
|
| plt.close() |
|
|
|
|
| if __name__ == "__main__": |
| plot_llm_share_heatmap() |
|
|