TL;DR
Just because a Python plotting script runs without crashing doesn’t mean the resulting chart makes any sense. When AI agents look at their own generated plots to fix mistakes, forcing them to separate what they see from what code to change rescues deeply broken charts—but also tempts them into "over-editing" and ruining plots that were already good. Building reliable visual agents isn't just about teaching them how to spot flaws, but teaching them when to put the paintbrush down.
What Problem Does This Paper Address?
If you’ve ever written matplotlib code late at night, you know the pain: zero syntax errors, clean execution, and an output chart that maps the wrong columns, scrambles the legend, or turns a 3D torus into a weird vase.
Code-only feedback loops can't catch these silent semantic failures. That’s why modern AI pipelines like MatPlotAgent add a multimodal "visual critic" to inspect the rendered image and suggest code repairs. However, standard critics do everything in one breath—perceiving the image, comparing it to the user's prompt, diagnosing bugs, and planning code edits in a single free-form response. Because observation and action are tangled together, the critic often misses subtle data-mapping errors on hard charts, or suggests nitpicky cosmetic tweaks that accidentally break good charts. And when a repair goes sideways, you can't tell if the AI misread the image or just overreacted in the code.
Methods
The author reproduces the standard MatPlotAgent pipeline (query expansion $\rightarrow$ code generation & debugging $\rightarrow$ visual feedback up to three iterations) and modifies only the visual-feedback prompt, keeping inputs and call limits identical.
Instead of free-form advice, the new structured critic creates an auditable text bottleneck split into two explicit steps:
VisualImagination(Diagnosis): A pure textual record of what the rendered figure currently looks like, explicitly separating satisfied requirements from missing or wrong ones, and pointing to likely causes in the code.RevisionInstruction(Repair Plan): Concrete code-level instructions specifying exact fixes alongside an explicit directive on what existing elements to preserve.
For evaluation, rather than relying solely on how closely a plot resembles a human reference image, the study emphasizes a query-conditioned rubric scored by multimodal LLM judges (GPT-5.4, GPT-4o, and Gemini 3.8 Flash) across task compliance, structure, visual encoding, and readability.
Datasets
The system is evaluated on MatPlotBench, an existing benchmark of 100 scientific visualization tasks. Each task pairs raw data (like CSVs) with a detailed user request and a human-verified ground-truth figure. Because MatPlotBench has no official validation split, the author used 30 baseline-stratified examples for prompt development and set aside the remaining 70 as a leakage-aware held-out set.
Key Insights and Ideas
- Plausibility is a trap: Standard critics often get fooled by surface resemblance—seeing a stacked bar chart with nice colors and giving it a pass, even though the numbers don't match the table. Forcing an explicit
VisualImaginationstep shifts the agent from checking plot family to verifying internal data relationships. - The curse of the perfectionist editor: Detailed critiques make minor observations sound authoritative. On a draft plot that is already 95% right, pointing out a tiny spacing or styling quirk gives the repair coder "permission" to rewrite fragile layout or data-generation code, degrading the plot.
- Bad repairs are mostly bad boundaries, not bad eyesight: In a manual audit of 17 degraded plots, only 3 failed because the critic misread the image; 13 failed because of excessive intervention. Better vision won't fix an over-eager editing policy!
- Simple "stop" gates backfire: Trying to prevent over-editing with a binary "no-revision gate" saved the easy plots, but caused the model to chicken out on hard, plausible-looking charts with deep structural flaws, wiping out the overall gains.
- More structure, lower cost: Even though the structured prompt was 59–90 tokens longer, it produced more concise responses—actually reducing total tokens, latency, and per-call cost across all tested models.
Key Results
Tested across three generation backbones (Gemini 3 Flash, GPT-5.4-mini, and Claude Haiku 4.5):
- Strong gains for Gemini, modest uncertainty for others: Under the GPT-5.4 rubric judge across all 100 tasks, structured critique boosted Gemini 3 Flash by +8.41 points (70.02 $\rightarrow$ 78.43, with a 95% bootstrap CI of
[5.28, 11.58], excluding zero). Gains for GPT-5.4-mini (+1.18) and Claude Haiku 4.5 (+0.62) were positive, though their confidence intervals crossed zero. - Held-out & cross-judge consistency: On the 70 held-out tasks, Gemini 3 Flash gained +8.81 (GPT-5.4 judge) and +9.24 (GPT-4o judge). On a frozen 30-case check scored by an independent Gemini 3.8 Flash judge, Gemini 3 Flash still gained +8.42 (
[4.64, 12.53]). - Where the magic happens: Gains concentrated heavily on broken drafts. In the lowest-scoring buckets (0–20 and 20–40), Gemini jumped +12.45 and +16.65 rubric points, and GPT-5.4-mini jumped +8.52 in the 20–40 bucket before slightly regressing on already-high-scoring charts.
Limitations and Future Work
All evaluations rely on automated multimodal LLM judges rather than human scientists, and GPT-5.4 was used to judge a related model family (GPT-5.4-mini). Additionally, experiments were run with a single generation seed, leaving small backbone differences statistically uncertain. Looking ahead, the central challenge for visual coding agents is calibrated intervention: designing critics that weigh the risk of touching working code against the reward of a major structural fix, knowing not just how to repair a figure, but when to leave it alone.
Summary updated