TL;DR
When humans write code to recreate a chart, we don't delete the whole script and start over every time a bar is the wrong color—we look at the rendered image, find the buggy line, and patch it. This paper brings that exact "generate, inspect, and patch" workflow to Multimodal Large Language Models (MLLMs). By training a tiny 2-billion-parameter diagnostic model to connect visual chart errors directly to specific lines of code, the authors achieve better plot-to-code generation than heavyweight multi-agent systems at a fraction of the compute cost.
What Problem Does This Paper Address?
Plot-to-code generation asks an AI to look at a data visualization (like a complex Matplotlib chart) and write executable code that reproduces it faithfully. Most existing MLLMs treat this as a single-shot game: look at the image, spit out the code in one pass, and hope for the best. Unsurprisingly, models frequently stumble on subtle details—missing legends, mismatched colors, or warped layouts.
To fix this, researchers have leaned on test-time scaling techniques like "Best-of-N" repeated sampling (generating dozens of full scripts and picking the best one) or complex multi-agent debates. Both approaches burn through massive amounts of tokens because they regenerate the entire program from scratch on every attempt, risking new bugs while fixing old ones. Worse, standard verifiers only give a thumbs-up or thumbs-down without explaining why a chart looks wrong or where the culprit hides in the source code.
Methods
Instead of brute-force regeneration, the authors introduce a Visual-Code Diagnostics framework built around a lightweight (2B parameter) diagnostic verifier.
First, the authors group plotting mistakes into four intuitive categories: compiler failures, data errors (wrong values/shapes), local styling errors (specific element colors/markers), and global layout/style inconsistencies.
During test time, the pipeline loops through four steps: generate, render, diagnose, and patch-refine. If the rendered chart doesn't match the reference image, the 2B verifier examines the reference chart, the generated chart, and the source code. It outputs two things:
- Visual Diagnostic: Which coarse-grained error categories occurred.
- Code Diagnostic: Where to fix it. Crucially, instead of predicting fragile line numbers—which LLMs are notoriously bad at counting—the verifier reprints the code with
# TODOcomments (e.g.,# TODO: Modify the following 1 lines) injected right above the suspicious lines.
The main generator then writes a localized code patch for just those flagged regions, leaving working code untouched.
To train this compact verifier without human annotators, the authors use Supervised Fine-Tuning (SFT) followed by Reinforcement Learning (GRPO, a memory-efficient RL algorithm). The RL reward uses Jaccard similarity—a measure of overlap between predicted and ground-truth sets—to give the model partial credit as it learns to pinpoint both error types and # TODO placements.
Datasets
- Diagnostic Verification Dataset (New): Starting with 1,000 clean chart-code pairs from Chart2Code-160k, the authors prompt GPT-4o to intentionally introduce realistic data, local style, and global style bugs. By pairing mutated scripts against each other and aligning their differences with an improved line-level Levenshtein distance algorithm, they automatically generate 12,000 structured training and evaluation examples.
- Evaluation Benchmarks: End-to-end plot-to-code performance is tested on two established benchmarks: ChartMimic and Plot2Code.
Key Insights and Ideas
- Targeted training beats raw scale for verification: A compact 2B verifier trained specifically on visual-code diagnostics consistently outperforms an untrained 32B model at guiding code refinement. Knowing how to connect pixels to Python syntax matters far more than parameter count.
- Code-friendly localization (
# TODOs): Framing code localization as inline# TODOcomments rather than numerical line indices plays naturally to how LLMs read context, making downstream patching much more reliable. - The "Specialist" Paradox: When the authors paired their diagnostic verifier with ChartMaster-7B—a model heavily fine-tuned specifically for one-pass plot-to-code generation—performance actually dropped (execution success fell from 93.7% to 71.9% on ChartMimic). Even when fed perfect, human-written diagnostics, ChartMaster-7B failed to edit its own code. Narrow domain fine-tuning appears to overwrite general instruction-following and code-editing skills!
Key Results
- Consistent gains across generators: Using Qwen3-VL-8B as the generator on ChartMimic, the RL-trained 2B verifier boosts execution success from 77.8% (one-pass) to 90.0%, and fine-grained visual similarity from 66.2 to 73.4. With GPT-4o, visual similarity climbs from 81.6 to 87.6 on ChartMimic and from 66.1 to 71.8 on Plot2Code.
- Massive efficiency wins: Compared to a GPT-4o multi-agent refinement baseline, this framework achieves a higher visual score (87.6 vs. 86.5) while slashing inference token consumption from 11,264 tokens down to 1,859.3 tokens—a 6.1× reduction in cost.
Limitations and Future Work
- Generator editing bottleneck: As revealed by the ChartMaster-7B experiments, test-time refinement is only as good as the generator's ability to follow editing instructions. Training specialized generators to retain code-revision skills is an open priority.
- Subtle visual details: Case studies show that while major layout and axis errors get resolved over 3–5 iterations, very fine-grained styling discrepancies can still slip through, pointing to a need for finer diagnostic granularity in future work.
Summary updated