Visual Programmability: A Guide for Code-as-Thought in Chart Understanding

Bohao Tang, Yan Ma, Fei Zhang, Jiadi Su, Ethan Chern, Zhulin Hu, Zhixin Wang, Pengfei Liu, Ya Zhang

TL;DR

Vision-Language Models (VLMs) often struggle with chart understanding because they rely on a single, rigid reasoning strategy—either pure visual analysis or code generation. This paper introduces Visual Programmability, an adaptive framework that teaches VLMs to dynamically choose whether to write code or reason visually based on the chart's complexity and the specific question asked. Trained via reinforcement learning with a novel dual-reward system, this approach achieves state-of-the-art performance across diverse chart benchmarks by knowing how and when to reason.

What Problem Does This Paper Address?

Charts are a unique challenge for AI because they sit at the intersection of low-level visual perception and high-level logical inference. Current Vision-Language Models (VLMs) typically tackle chart understanding in one of two ways: they either act as a controller for a fixed set of external tools, or they are fine-tuned to use a single reasoning mode, such as text-based Chain-of-Thought (CoT) or code-generation (Code-as-Thought).

Both approaches suffer from strategic rigidity. Tool-use models break when a chart requires a function outside their predefined toolkit. On the other hand, code-centric models excel at highly structured data but catastrophically collapse on complex, "in-the-wild" scientific charts due to numerical hallucination—where the model writes flawless code based on a fundamentally flawed visual perception of the chart.

Figure 2: Performance of Fixed Strategies Highlights a Critical Trade-off. While the Code-as- Thought (CaT) strategy excels on structured charts (ChartX), its performance collapses on complex, ’in-the-wild’ charts (CharXiv). All values are accuracy (%).

Methods

To solve this, the authors propose an adaptive framework based on the concept of Visual Programmability (VP)—a learnable, task-dependent property that determines if a chart-question pair is better solved via programmatic reasoning or direct visual analysis.

The system explicitly factorizes the reasoning process. Given an image and a question, the VLM first outputs a strategy token (<CODE> or <DIRECT>), which routes the model into one of two pathways:

  1. Code-based Path (<CODE>): The model writes Python code to parse the chart into a structured format (like a pandas DataFrame) and computes the exact answer. This is ideal for high-VP tasks.
  2. Direct Path (<DIRECT>): The model generates a natural language CoT based on holistic visual perception, which is essential for complex or artistic charts where code decomposition would lose critical information.
Overview of the adaptive reasoning framework and GRPO training pipeline.

To train this selection policy without explicit ground-truth strategy labels, the authors use Group Relative Policy Optimization (GRPO), a reinforcement learning algorithm. They introduce a comprehensive dual-reward system:

  • Accuracy Reward ($r_{acc}$): A binary reward based on the correctness of the final answer.
  • Decision Reward ($r_{decision}$): Incentivizes choosing the correct strategy based on pre-annotated VP labels, preventing the model from collapsing into a single mode.
  • Data Accuracy Reward ($r_{data}$): Programmatically compares the model's generated DataFrame against a ground-truth data table to ensure the code is factually grounded, mitigating numerical hallucination.

Datasets

  • Training Data: Built upon ChartMimic (4,800 chart-code pairs), which the authors expanded by generating synthetic question-answer pairs using Gemini-2.5-Flash to create a balanced dataset of both highly programmable and visually dominant tasks.
  • Evaluation Benchmarks: Evaluated across four distinct benchmarks representing a wide spectrum of visual programmability:
  • ChartX: Highly structured charts testing code-based precision.
  • ChartBench: Focuses on numerical reasoning requiring visual interpolation.
  • ChartQA: Real-world charts with human and template-generated questions.
  • CharXiv: Complex, "in-the-wild" scientific charts with high visual complexity.

Key Insights and Ideas

  • Strategic Cognition over Monolithic Scaling: The paper shifts the focus from making VLMs better at a single tool (like coding) to teaching them when to deploy that tool. True robustness emerges from meta-cognitive strategy selection.
  • Task Dependency: Visual Programmability is not just an intrinsic property of the chart itself; it depends heavily on the query. A chart might have high VP for a simple counting question ("How many lines are plotted?") but low VP for a precise value-extraction task on a logarithmic scale.
  • Verifiable Intermediate States: By forcing the model to generate structured data frames when coding, the framework introduces a verifiable intermediate step that can be directly evaluated against ground truth during RL training, grounding the model's logic in hard facts.

Key Results

  • The adaptive RL model achieved the highest average accuracy (62.8%) across all four benchmarks, outperforming both standard text CoT and fixed code CoT baselines.
  • The model successfully learned dynamic strategy modulation: it utilized code-based reasoning heavily on high-VP benchmarks (76.0% on ChartX) but automatically throttled code usage to just 10.1% on the complex CharXiv benchmark to avoid hallucination pitfalls.
  • The framework scales effectively to larger model sizes, achieving top performance when implemented on a 32B parameter model scale.
Training dynamics on ChartX showing how the Data Accuracy Reward helps the model learn when data fidelity is high or low.

Limitations and Future Work

  • Coarse Binary Decisions: The current framework treats strategy selection as a binary choice (<CODE> vs <DIRECT>). Future work aims to develop hybrid, granular models that can use code for data extraction while concurrently using visual reasoning for qualitative patterns, or perform region-based assessments on a single complex figure.
  • Expanding Formal Reasoning Vocabularies: The current "Code-as-Thought" process is restricted to data analysis logic. The authors suggest expanding this to internal symbolic languages for signal processing (for time-series) or graph theory (for network diagrams).
  • Reducing Annotation Dependency: The current training relies on pre-annotated programmability labels. A key future direction is self-supervised policy learning, where the model discovers the decision boundary autonomously by correlating its strategy choices directly with final task success.

Summary updated

BibTeX
@misc{tang2025visual,
  author = {Bohao Tang and Yan Ma and Fei Zhang and Jiadi Su and Ethan Chern and Zhulin Hu and Zhixin Wang and Pengfei Liu and Ya Zhang},
  title = {{Visual Programmability: A Guide for Code-as-Thought in Chart Understanding}},
  year = {2025},
  eprint = {2509.09286},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2509.09286},
}
Figure