Abstract
The chart-to-code generation task requires MLLMs to convert chart images into executable code. This task faces two main challenges: limited data diversity and the difficulty of maintaining visual consistency between generated charts and the original ones. Existing datasets mainly rely on synthetic seed data to prompt GPT models for code generation, resulting in homogeneous samples that limit model generalization to real-world chart styles. To address this, we propose ReChartPrompt, leveraging real-world, human-designed charts extracted from arXiv papers as prompts. By harnessing the rich content and diverse visual styles of arXiv charts, we construct ReChartPrompt-240K, a large-scale and highly diverse dataset that better reflects realistic chart variations. For the second challenge, although SFT improves code understanding by optimizing next-token prediction, it does not provide direct supervision on visual features. As a result, it often fails to guarantee that the generated charts visually match the original ones. To address this, we propose ChartSimRL, a GRPO-based reinforcement learning algorithm guided by a novel chart similarity reward. This reward consists of two components: attribute similarity, which measures the overlap of chart attributes like layout and color between the generated and original charts, and visual similarity, which evaluates overall visual features, including texture, using convolutional neural networks. Unlike traditional text-based rewards, our reward accounts for the multimodal nature of the chart-to-code generation task, significantly enhancing the model's ability to accurately reproduce charts. Integrating ReChartPrompt and ChartSimRL, we develop the ChartMaster model, achieving SOTA results among 7B-parameter models and rivaling GPT-4o on various chart-to-code benchmarks.
Introduction
While Multimodal Large Language Models (MLLMs) have become increasingly capable, the specific task of chart-to-code generation—taking an image of a graph and writing the Python code to recreate it—remains a major hurdle. Current research identifies two primary bottlenecks: data homogeneity and the "blind" training gap. Existing training sets rely on synthetic data generated from limited seeds, lacking the visual complexity of real-world scientific visualizations. Furthermore, standard Supervised Fine-Tuning (SFT) focuses on next-token prediction rather than visual fidelity, often leading to code that produces charts with incorrect colors, missing labels, or shifted axes.
Methodology
ReChartPrompt: Leveraging Real-World Diversity
To address data homogeneity, we developed ReChartPrompt, a pipeline that moves beyond synthetic data. By scraping over 30,000 arXiv papers, we identified real, human-designed charts and used a powerful teacher model (Qwen2.5-VL-72B) to reverse-engineer their code. After rigorous filtering for execution errors, we produced ReChartPrompt-240K, a high-diversity dataset of 240,000 chart-code pairs that better reflects realistic scientific variations.
ChartSimRL: Reinforcement Learning with Visual Feedback
To ensure visual consistency, we implemented ChartSimRL, a reinforcement learning stage using Group Relative Policy Optimization (GRPO). Unlike traditional text-based rewards, our "Chart Similarity Reward" incorporates:
- Attribute Similarity: Measuring the overlap of semantic data like layout, text, and color.
- Visual Similarity: Utilizing a pre-trained ResNet-18 to compare deep visual features and textures between the original and generated images.
Results
ChartMaster-7B achieves state-of-the-art (SOTA) results among open-source 7B-parameter models, rivaling proprietary models like GPT-4o.
On the ChartMimic benchmark, ChartMaster-7B achieved a 93.8% execution rate, slightly outperforming GPT-4o (93.2%) and significantly surpassing its own baseline. Across Plot2Code and ChartX, the model consistently demonstrated superior performance in text-matching and overall rating scores. Qualitative results show that ChartMaster is particularly adept at capturing complex elements, such as specific arrow styles in vector fields or exact color palettes in heatmaps, which are typically ignored by SFT-only models.
Conclusion
By integrating the diverse real-world data of ReChartPrompt with the visual-centric reinforcement learning of ChartSimRL, ChartMaster sets a new standard for chart-to-code generation. This work demonstrates that specialized training strategies can enable efficient 7B-parameter models to match the performance of much larger, closed-source systems.
Summary updated