Shanghai Jiao Tong's ChartIR Beats GPT-4o at Turning Charts Into Code
ChartIR splits chart-to-code into visual understanding and code translation, then iteratively refines the output. It beats METAL on GPT-4o and Qwen2-VL.
ProTakeaways
- ChartIR is a training-free, model-agnostic framework for chart-to-code generation from SJTU and Lehigh.
- It splits the task into visual understanding and code translation using two structured prompts: description and difference.
- A two-stage pipeline generates initial code, then iteratively refines it until an aggregate similarity score stops improving.
- Beats METAL and direct prompting on Plot2Code and ChartMimic with both GPT-4o and Qwen2-VL.
- Biggest gain: Qwen2-VL on ChartMimic jumps from 2.20 to 3.86 GPT-4o Score, a 75 percent relative lift.
- Ablations show the description matters most for open models; strong closed models see smaller returns.
Getting a multimodal model to look at a chart and produce matplotlib code that reproduces it sounds like it should be a solved problem. In practice, even GPT-4o stumbles on colors, legend positions, tick labels, and subplot layouts. A new method called ChartIR, from researchers at Shanghai Jiao Tong University and Lehigh, addresses this by turning the task into a structured conversation between the model and itself, with two stages and two specific prompt types.
The paper reports consistent gains over both direct prompting and METAL, the previous state-of-the-art iterative approach, on the Plot2Code and ChartMimic benchmarks, without additional training on the closed-source side.
Why chart-to-code trips up strong models
The task asks an MLLM to generate executable code that reproduces a given chart, demanding precise visual understanding and accurate translation of visual elements into structured code. The authors argue that failures come from two distinct bottlenecks that most systems try to solve in one shot. Visual understanding refers to the model's ability to extract accurate and multi-dimensional information such as structure, text, colors, and layout from the input. Code translation involves converting that rich visual information into executable and semantically faithful code.
Prior work took two routes. ChartCoder improves performance by decomposing the generation process into step-by-step procedures and applying instruction tuning to open-source models, but it requires training and cannot touch closed models. METAL used a training-free multi-agent loop, but the authors identify a real weakness: it updates code based only on the lowest-performing single metric, which often leads to unbalanced optimization, and some metrics such as color are rarely used in practice. Optimizing one metric can degrade others, and relying on a single score for update decisions can yield code that is worse overall.