TL;DR
CodePlot-CoT introduces a novel code-driven Chain-of-Thought paradigm that empowers Vision Language Models (VLMs) to perform precise mathematical visual reasoning by generating executable plotting code as "visual thoughts." Along with a new 178K-sample dataset (Math-VR) and a specialized image-to-code converter (MatplotCode), this approach yields up to a 21% performance boost over standard text-only baselines by replacing unreliable pixel generation with precise, programmatic figures.
What Problem Does This Paper Address?
When humans solve complex math problems, we rarely rely on text alone; we sketch diagrams, plot functions, and draw auxiliary lines to make abstract relationships concrete.
Current Large Language Models (LLMs) and Vision Language Models (VLMs) face a critical bottleneck here. Most are constrained to text-only reasoning chains. While some unified multimodal models can generate interleaved text and images, they lack the pixel-level precision and controllability required for mathematics. Direct image generation (e.g., via diffusion models) struggles to satisfy strict geometric constraints, such as rendering an exact $90^\circ$ angle or perfectly connecting specific vertices.
The authors address this gap by proposing a framework where models can actively "think with images" using structured, verifiable code rather than raw pixels.
Methods
The core innovation is the CodePlot-CoT Paradigm, which shifts the burden of visual generation from pixel-level distribution modeling to a language modeling task where VLMs are already strong: writing code.
- Code-Driven Visual Thoughts: When a visual reasoning step is required (e.g., adding an auxiliary line), the VLM generates a block of executable Python plotting code (using
matplotlib). - External Execution: The code is executed externally to render a precise geometric image.
- Multimodal Feedback Loop: The rendered image is fed back into the VLM's context window as visual evidence, allowing the model to "see" its own visual thought and refine its final answer.
To curate high-quality training data for this paradigm, the authors also developed MatplotCode, a state-of-the-art image-to-code converter tailored for mathematical figures. It translates static geometry diagrams and function plots back into clean, executable Python code.
Datasets
The authors introduce Math-VR, the first large-scale, bilingual (English and Chinese) dataset and benchmark specifically designed for mathematical problems requiring visual reasoning.
- Size: 178,150 total samples (173K for training, 5K for benchmarking).
- Composition: Divided into a Text subset (2k text-only questions requiring visual imagination) and a Multimodal subset (3k questions accompanied by geometric images).
- Distribution: Geometry dominates the dataset at roughly 77%, with the remainder spanning Algebra, Calculus, and Statistics.
Key Insights and Ideas
- Code as the Optimal Visual Representation: Mathematical figures do not require texture or pixel-level fidelity; they require precise structural attributes (shapes, lengths, angular relationships). Programmatic code is the perfect intermediate representation for these structured properties.
- Active vs. Passive Vision: Prior benchmarks focused primarily on passive visual perception (e.g., reading information from a given chart). Math-VR demands active visual reasoning, where the model must manipulate or construct visual aids to uncover hidden geometric properties.
Key Results
The authors evaluated CodePlot-CoT against a suite of state-of-the-art models using two metrics: Answer Correctness (AC) and Process Score (PS).
- Performance Leap: Built on top of Qwen2.5-VL-32B, CodePlot-CoT achieved an absolute performance increase of up to 21% in Answer Correctness on the Math-VR benchmark.
- Scale Defiance: The 32B CodePlot-CoT model significantly outperformed much larger open-source models, including the 72B variant of Qwen2.5-VL, demonstrating that structured visual reasoning mechanisms can be more decisive than raw parameter scale.
- Converter Fidelity: In head-to-head evaluations, MatplotCode achieved a 100% execution success rate, vastly outperforming frontier closed-source models like GPT-o3 (79.6%) and Gemini-2.5-Pro (86.2%) when converting complex mathematical figures to code.
Limitations and Future Work
Despite these advances, a significant performance gap remains. Even the strongest closed-source model evaluated (Gemini-2.5-Pro with internal thinking enabled) still fails on approximately one-third of the Math-VR benchmark problems.
Additionally, the current framework relies on an external Python interpreter to execute code and return images to the context window. Future work will likely explore tighter, more native integrations of these programmatic visual loops directly within the model's architecture to improve inference efficiency and controllability.
Summary updated