File size: 4,863 Bytes
8c10cf2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c4e7970
 
 
8c10cf2
 
 
 
c4e7970
 
 
 
 
 
 
 
 
 
 
 
 
8c10cf2
 
c4e7970
8c10cf2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c4e7970
 
 
8c10cf2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/usr/bin/env python3
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

# Use Times New Roman globally for the figure
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),
    ]

    # Reorder columns within each series as CrewAI, MCP, A2A, A2A Mix
    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)

    # Series names as a common base label under each group
    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

    # Compact margins so bottom labels are close to suffixes and legend is tight
    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()