ChartMaster: Advancing Chart-to-Code Generation with Real-World Charts and Chart Similarity Reinforcement Learning
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 nexttoken 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 Chart- Master model, achieving SOTA results among 7B-parameter models and rivaling GPT-4o on various chart-to-code benchmarks. All resources are available at https://github.com/WentaoTan/ChartMaster.
Introduction. The chart-to-code generation task aims to automatically convert chart images into executable code (Yang et al., 2024a), enabling applications including automated data analysis, report generation, and intelligent question answering (Zhao et al., 2025). This task is challenging as it requires accurate visual understanding, cross-modal reasoning, and advanced code synthesis. Although recent advances in Multimodal Large Language Models (MLLMs) show promising results in various vision-language tasks, their performance on chart-to-code generation remains limited due to the unique complexity of charts and the need for precise code output.
Prior work, such as ChartCoder (Zhao et al., 2025), advanced the field by building the large Chart2Code-160K dataset. This dataset is synthesized by guiding GPT-4o (Hurst et al., 2024) with predefined chart attributes like chart type, color, and text. While this approach reduces the need for costly manual annotations and achieves strong performance, relying on predefined attribute seeds can introduce homogeneity and limit variability in the resulting dataset (see Appendix Fig. 5), potentially restricting model generalization to diverse real-world charts.
To address this limitation, we introduce Real-world Chart Prompt Code Generation (ReChart- Prompt), a novel automated pipeline that extracts real chart images from arXiv papers and leverages the Qwen2.5-VL-72B model (Bai et al., 2025) to generate corresponding code. By collecting 30,071 papers and utilizing their author-designed charts as prompts, we construct ReChartPrompt- 240K, a large-scale dataset comprising 240K chart–code pairs. Since these charts originate from papers across diverse research fields and exhibit a wide variety of design styles, the dataset captures rich visual and semantic diversity, as illustrated in Fig. 5. This heterogeneity enables effective generalization to real-world scenarios.
While supervised fine-tuning with diverse data can help models generate better chart code, such next-token prediction alone does not ensure the output charts are visually faithful to the references. As shown in Fig. 4, the SFT model produces charts closer to the ground truth than the baseline, but noticeable discrepancies remain in color, element positioning, and other visual attributes. To address this, we propose ChartSimRL, a reinforcement learning algorithm based on Group Relative Policy Optimization (GRPO) (Shao et al., 2024), guided by a novel chart similarity reward. Specifically, the reward jointly considers (1) attribute similarity that evaluates the consistency of chart elements such as textual content, numerical values, layout and color, and (2) visual similarity, which assesses holistic visual resemblance using convolutional neural networks (e.g., ResNet (He et al., 2016)) to extract and compare visual features. To the best of our knowledge, this is the first reward system that explicitly enforces multimodal visual-semantic consistency for chart-to-code generation. By encouraging models to produce code that renders charts both semantically accurate and visually faithful, we address a critical gap in prior research and support more robust generalization to realworld chart reproduction.
In summary, we introduce ChartMaster, an efficient framework for chart-to-code generation that combines the ReChartPrompt data generation pipeline with the ChartSimRL reinforcement learning strategy. Our key contributions are: (1) ReChartPrompt, an automated method for generating diverse datasets from real-world charts; (2) ChartSimRL, a reinforcement learning algorithm that uses both visual and attribute similarity to improve output; and (3) ChartMaster-7B, a compact model that delivers near GPT-4o performance with only 7 billion parameters. Fig. 1 highlights its efficiency and effectiveness.
Related work. Among multimodal code generation tasks, chart-to-code translation has emerged as a critical challenge (Yang et al., 2024b). Existing benchmarks include Design2Code (Si et al., 2024), which evaluates HTML generation using CLIP scores (Radford et al., 2021) and structural HTML metrics, and Plot2Code (Wu et al., 2024), which assesses both code correctness and visual fidelity. However, since the datasets for Design2Code and Plot2Code are sourced from the web, there is a risk of data leakage, which may compromise the reliability of model evaluation. To address this issue, Chart- Mimic (Yang et al., 2024a) provides a manually curated dataset of 4,800 chart-code pairs, along with additional fine-grained evaluation metrics.
Despite these benchmarks, large-scale chart-to-code training datasets remain scarce. ChartCoder (Zhao et al., 2025) addresses this by creating Chart2Code-160K, the first large-scale training set generated by guiding GPT-4o with predefined chart attributes such as type, color, values, and titles. It further employs the “Snippet of Thought” strategy (Zheng et al., 2023; Luo et al., 2024) to decompose code generation into structured steps, significantly boosting chart reasoning. Yet, reliance on fixed attributes limits chart diversity. In contrast, our ReChartPrompt leverages real-world charts from arXiv papers as prompts, yielding more diverse and representative chart–code pairs.
Reinforcement learning (RL) effectively enhances model capabilities Wang et al. (2024b); Milani et al. (2024); Tan et al. (2025c). For example, RL from human feedback (RLHF) Bai et al. (2022) and direct preference optimization (DPO) Rafailov et al. (2023) aligned model outputs with human preferences, improving complex reasoning and output quality. Building on these advances, Group Relative Policy Optimization (GRPO) Shao et al. (2024) was proposed as a novel RL algorithm that updated policies using relative rewards computed from groups of samples. DeepSeek-R1 Guo et al. (2025) employed simple yet effective rewards based on output accuracy and response format, which enabled stable training and emergent reasoning such as reflection and “a-ha” moments.
Inspired by DeepSeek-R1’s success, recent work extended GRPO-based RL to MLLMs (Tan et al., 2025a; Zhang et al., 2025b; Peng et al., 2025; Shen et al., 2025) in two main directions. The first adapts R1’s method to MLLMs—for instance, Vision-R1 (Huang et al., 2025) uses SFT data with reflection for cold-start training and applies GRPO with accuracy- and format-based rewards. Similarly, MM-EUREKA (Meng et al., 2025) refines reward design and loss functions, successfully reproducing the visual “aha moment,” where the model revisits images “upon closer inspection.”
Method. Fig. 2 illustrates the overall framework of ChartMaster, which consists of two main stages: data generation and model training.
To improve dataset diversity, we use real-world chart images as input to guide code generation, as shown in Fig. 2 (a). This approach captures richer styles and content that predefined attribute seeds cannot represent.
ChartMaster is trained in two stages: (1) SFT on the ReChartPrompt-240K dataset to establish a solid foundation; and (2) further optimized with ChartSimRL to address the limitations of SFT’s next-token prediction in maintaining visual consistency.
Supervised Fine-Tuning. We conduct SFT by maximizing the likelihood of ground-truth code Yi given chart image Ii and instruction Ti:
Reinforcement Learning with ChartSimRL. While SFT strengthens the model’s basic capability, discrepancies may still exist between the generated charts and the originals (see Fig. 4). To further improve reproduction fidelity, we continue training the model using ChartSimRL, as illustrated in Fig. 2 (b). Specifically, for each training sample (I, T, Y ), the model samples a group of M candidate codes: {O1, O2, . . . , OM} ∼πθ(· | I, T).
Each candidate code Oi is then executed to generate a chart image ˆIi, which is subsequently compared with the original chart Ii to compute a Chart Similarity Reward. If the execution of Oi fails, the corresponding reward is set to zero.
Chart Similarity Reward. Traditional reward functions, such as the accuracy reward used in (Guo et al., 2025; Huang et al., 2025), primarily assess the consistency between generated text and groundtruth text. However, the chart-to-code task is inherently multimodal, involving both code and generated charts, requiring evaluation of not only semantic correctness but also visual alignment. To this end, we design a novel chart similarity reward as:
Here, Rattr i measures the semantic consistency, and Rvis i captures visual similarity (see Fig. 2 (c)).
Attribute Similarity: We develop a semantic attribute extraction tool, denoted G(·), to obtain attribute sets from chart images and their code. Given Ai = G(ˆIi, Oi) and A∗= G(I, Y ), the semantic similarity Rattr i is computed as their Jaccard similarity:
By design, Rattr i = 1 indicates a perfect match of semantic attributes, while lower values reflect semantic discrepancies. To accommodate minor numerical variations, we consider numerical values a ∈Ai and b ∈A∗matching if |a −b| ≤0.01 × |b|.
Visual Similarity: We use a pretrained ResNet-18 network (He et al., 2016) F = {F1, F2, F3, F4} to extract feature maps from both I and ˆIi. Here, Fk(·) ∈RCk×Hk×Wk denotes the output feature map of the k-th residual block. We extract the feature map and flatten them into vectors like:
Chart Similarity Reinforcement Learning. We normalize rewards within a group of M candidates to compute relative advantages:
Following the GRPO framework (Shao et al., 2024), we update the model by maximizing the clipped surrogate objective with a KL penalty to stabilize training:
ChartSimRL guides the model to generate chart code that better aligns with the original charts’ semantic and visual properties, significantly improving chart-to-code generation performance beyond what is achievable by supervised fine-tuning alone.
Summary. ReChartPrompt and ChartSimRL have been effectively integrated into the ChartMaster framework. This framework not only leverages real-world data for enhanced data diversity but also employs a novel algorithm to ensure visual and semantic alignment in chart reproduction. Consequently, ChartMaster stands as a comprehensive solution for the chart-to-code generation task, demonstrating marked improvements in performance and generalization capabilities.
Discussion. Based on extensive experiments, we observe that ReChartPrompt generates charts with diverse and rich attributes, enabling the construction of a high-quality dataset that substantially enhances model performance. Building upon the distinctive features of the chart-to-code generation task, we propose the ChartSimRL algorithm, which further enhances the model’s capabilities. To comprehensively analyze the improvements brought by these contributions, we conduct a qualitative comparison of generated charts at different training stages on the ChartMimic benchmark (Fig. 4). Our key findings are summarized as follows: (1) The baseline model produces basic chart layouts but often fails
Conclusion. In this paper, we propose ChartMaster, a novel chart-to-code generation framework paired with a tailored reinforcement learning algorithm. By introducing ReChartPrompt, we address data homogeneity issues in prior work and build a highly diverse ReChartPrompt-240K dataset. Our ChartSimRL algorithm combines semantic and visual similarity rewards, enabling the model to generate chart code that closely matches original visuals. Experiments show ChartMaster achieves performance on par with GPT-4o in chart-to-code tasks. We will open source all resources to foster community development and advance research in this area.
Beyond its technical innovations, ChartMaster supports automated scientific reporting and empowers data-driven decision-making across a wide range of domains. While our current framework targets common chart types and Python-based code, expanding its scope to include a wider range of chart formats and programming languages is an exciting direction for future work.
Lines of inquiry this paper opens 24
Research framings built by reading the notes related to this paper — the questions it feeds into.
Can visual rendering-based rewards effectively improve code and layout quality?- How does rendering and measuring beat vision-language models for slide assessment?
- Can bounding-box signals replace image encoders for visual output evaluation?
- Why do vision-based rewards for web generation incur substantial computational overhead?
- Can matching UI elements by text similarity and position handle visually equivalent but structurally different layouts?
- What performance gains does ALISA achieve over prior WebUI-to-Code training methods?
- Does the rendering reward generalize beyond chart editing to other code generation tasks?
- How does the rendering reward weight code executability against visual fidelity failures?
- What layout and text metrics does ChartEditor use to measure visual fidelity?
- Can Chamfer Distance and code validity capture whether designs match an engineer's intent?
- Does format reward contribute independently to CAD-Coder's final performance?
- What signals matter more for UI evaluation: rendered visuals or symbolic descriptions?
- Do quality ceiling effects appear in other visual domains beyond game UI?
- Can render-and-judge mechanisms generalize beyond chart-to-code to other executable outputs?
- Can professional design workflows integrate vector generation from pretrained vision-language models?
- Which reward component matters most: pixel reconstruction, semantic similarity, or code efficiency?
- How does visual-similarity reward resolve semantic equivalence problems in code?
- Can visual rendering rewards work for tasks beyond code reconstruction?
- What makes code-matching training brittle compared to image-matching training?
- What limits SlideCoder to single-slide generation from reference images?
- How does render-and-compare training differ from expert-judged rewards in visual tasks?
- Do vision-language models learn design taste differently than structure recognition?
- Has the MLLM visual critic been validated against human judgments of front-end quality?
- How does color-gradient segmentation compare to learned visual decomposition for slides?