"""Generate the PARA vs ACT bar chart as an SVG."""
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import numpy as np

tasks = ["Pick & Place", "Fold Towel", "Wipe Table"]
para = [97, 97, 95]
act = [9, 11, 0]

PARA_COLOR = "#16653a"
ACT_COLOR = "#a12029"

x = np.arange(len(tasks))
w = 0.36

fig, ax = plt.subplots(figsize=(8.0, 5.0), dpi=120)
b1 = ax.bar(x - w / 2, para, w, label="PARA", color=PARA_COLOR, edgecolor="white", linewidth=1.2)
b2 = ax.bar(x + w / 2, act, w, label="ACT", color=ACT_COLOR, edgecolor="white", linewidth=1.2)

for bars in (b1, b2):
    for bar in bars:
        h = bar.get_height()
        ax.annotate(f"{h}%",
                    xy=(bar.get_x() + bar.get_width() / 2, h),
                    xytext=(0, 4), textcoords="offset points",
                    ha="center", va="bottom",
                    fontsize=11, fontweight="bold", color="#222")

ax.set_xticks(x)
ax.set_xticklabels(tasks, fontsize=12)
ax.set_ylabel("Success Rate (%)", fontsize=12)
ax.set_ylim(0, 110)
ax.set_yticks([0, 25, 50, 75, 100])
ax.set_title("Real Robot Results: PARA vs ACT (20 demos)",
             fontsize=14, fontweight="bold", pad=14)
ax.legend(fontsize=12, frameon=False, loc="upper right")
ax.spines["top"].set_visible(False)
ax.spines["right"].set_visible(False)
ax.grid(axis="y", linestyle="--", alpha=0.4)
ax.set_axisbelow(True)

plt.tight_layout()
plt.savefig("/data/cameron/penpot/figures/bar_chart.svg", format="svg", bbox_inches="tight")
plt.savefig("/data/cameron/penpot/figures/bar_chart.png", format="png", bbox_inches="tight", dpi=120)
print("Wrote bar_chart.svg and bar_chart.png")
