PlotTwin-Bench / scorer /examples /quickstart.py
ritianzhaoxx's picture
Add the PlotTwin-Bench scorer and a quickstart example
0610fc9 verified
Raw History Blame Contribute Delete
1.28 kB
"""Score a simple baseline on a few PlotTwin-Bench tasks.
Every task gives a reference figure and a target CSV. A method writes one plotting
script per task, `<id>.py`, that reads the target data from `data.csv` and saves one
PNG. This example writes a default-style pandas plot for the first three tasks and
scores it:
cd scorer
export OPENAI_API_KEY=... # plus OPENAI_BASE_URL for a compatible endpoint
uv run python examples/quickstart.py
"""
from pathlib import Path
from datasets import load_dataset
from plottwin_scorer.cli import main as plottwin_score
BASELINE = '''\
import matplotlib.pyplot as plt
import pandas as pd
df = pd.read_csv("data.csv")
df.select_dtypes("number").iloc[:, :3].plot(figsize=(6, 4))
plt.tight_layout()
plt.savefig("figure.png", dpi=150)
'''
bench = load_dataset("figmirror/PlotTwin-Bench", split="test")
pred_dir = Path("quickstart_preds")
pred_dir.mkdir(exist_ok=True)
for row in bench.select(range(3)):
# A real method reads row["reference_image"] and row["target_data"] here.
(pred_dir / f"{row['id']}.py").write_text(BASELINE)
# Same as: uv run plottwin-score --pred-dir quickstart_preds --out-dir quickstart_scores
plottwin_score(["--pred-dir", str(pred_dir), "--out-dir", "quickstart_scores"])