| import matplotlib.pyplot as plt |
| import matplotlib.style as style |
| from matplotlib.ticker import PercentFormatter |
| import os |
| import argparse |
| import numpy as np |
|
|
|
|
| def create_accuracy_plot(save_path=None, save_dir=None): |
| """ |
| Parameters: |
| ----------- |
| save_path : str, optional |
| Filename to save the figure. If None, the figure is not saved. |
| save_dir : str, optional |
| Directory to save the figure. If provided, the directory will be created |
| if it doesn't exist. Default is current directory if save_path is provided. |
| |
| Returns: |
| -------- |
| fig, ax : tuple |
| Figure and axes objects for further customization if needed. |
| """ |
| style.use("seaborn-v0_8-whitegrid") |
| plt.rcParams["font.family"] = "sans-serif" |
| plt.rcParams["font.sans-serif"] = ["Arial", "DejaVu Sans"] |
| plt.rcParams["font.size"] = 16 |
| plt.rcParams["axes.labelsize"] = 16 |
| plt.rcParams["axes.titlesize"] = 17 |
| plt.rcParams["xtick.labelsize"] = 12 |
| plt.rcParams["ytick.labelsize"] = 12 |
| plt.rcParams["legend.fontsize"] = 12 |
|
|
| |
| models = [ |
| "Magentic-One", |
| "Magentic-UI\n(autonomous)", |
| "Magentic-UI +\nSimulated User\n(smarter model)", |
| "Magentic-UI +\nSimulated User\n(side-information)", |
| "Human", |
| ] |
| accuracy = [33.72, 30.2, 42.6, 51.9, 92] |
| sample_size = 162 |
|
|
| |
| z = 1.96 |
| accuracy_frac = np.array(accuracy) / 100.0 |
| ci_half_width = ( |
| z * np.sqrt(accuracy_frac * (1 - accuracy_frac) / sample_size) * 100 |
| ) |
|
|
| |
| fig, ax = plt.subplots(figsize=(9, 6)) |
|
|
| |
| dark_magenta = "#8B008B" |
| grey = "#808080" |
| beige = "#F5F5DC" |
|
|
| colors = [grey, dark_magenta, dark_magenta, dark_magenta, beige] |
| hatches = [ |
| "", |
| "", |
| "///", |
| "xx", |
| "", |
| ] |
|
|
| |
| x = np.arange(len(models)) * 2 |
|
|
| |
| bars = [] |
| for i, (model, acc) in enumerate(zip(models, accuracy)): |
| bar = ax.bar( |
| x[i], |
| acc, |
| color=colors[i], |
| width=1, |
| edgecolor="black", |
| linewidth=0.8, |
| label=model, |
| hatch=hatches[i], |
| yerr=ci_half_width[i], |
| capsize=8, |
| ) |
| bars.extend(bar) |
|
|
| |
| ax.set_xticks(x) |
| ax.set_xticklabels(models, rotation=0, ha="center") |
| |
| ax.set_ylabel("Accuracy (%)", fontweight="bold") |
| ax.set_ylim(0, 100) |
| ax.yaxis.set_major_formatter(PercentFormatter()) |
|
|
| |
| ax.yaxis.grid(True, linestyle="--", alpha=0.7) |
| ax.set_axisbelow(True) |
|
|
| |
| ax.spines["top"].set_visible(False) |
| ax.spines["right"].set_visible(False) |
|
|
| |
| ax.spines["left"].set_linewidth(1.5) |
| ax.spines["bottom"].set_linewidth(1.5) |
|
|
| |
| legend = ax.legend( |
| loc="upper left", frameon=True, framealpha=0.9, edgecolor="lightgray" |
| ) |
| legend.get_title().set_fontweight("bold") |
|
|
| |
| plt.xticks(rotation=0, ha="center") |
|
|
| |
| plt.subplots_adjust(bottom=0.15) |
|
|
| plt.tight_layout() |
|
|
| |
| if save_path: |
| if save_dir: |
| |
| os.makedirs(save_dir, exist_ok=True) |
| full_path = os.path.join(save_dir, save_path) |
| else: |
| full_path = save_path |
| |
| plt.savefig(full_path.replace(".png", ".pdf"), dpi=600, bbox_inches="tight") |
| |
| plt.savefig(full_path.replace(".pdf", ".png"), dpi=600, bbox_inches="tight") |
| print( |
| f"Plot saved to: {os.path.abspath(full_path.replace('.png', '.pdf'))} and {os.path.abspath(full_path.replace('.pdf', '.png'))}" |
| ) |
|
|
| return fig, ax |
|
|
|
|
| if __name__ == "__main__": |
| |
| parser = argparse.ArgumentParser(description="plot experimental results") |
| parser.add_argument( |
| "--save-dir", |
| "-d", |
| type=str, |
| default="plots", |
| help="Directory to save the plot (default: plots)", |
| ) |
|
|
| args = parser.parse_args() |
|
|
| |
| fig, ax = create_accuracy_plot( |
| save_path="model_accuracy_comparison.png", save_dir=args.save_dir |
| ) |
|
|