TL;DR
This paper introduces ChartIR, a novel framework that significantly improves the ability of multimodal large language models (MLLMs) to generate executable code from chart images. By breaking down the process into structured instruction-based visual understanding and iterative refinement, ChartIR achieves state-of-the-art performance on challenging chart-to-code generation tasks.
What Problem Does This Paper Address?
Generating accurate code that reproduces a given chart image is a surprisingly difficult task for current multimodal large language models (MLLMs). While MLLMs excel at many vision-language tasks, they often struggle with chart-to-code generation because it requires not only understanding complex visual information (like data points, labels, colors, and layout) but also translating that information into precise, executable code. Simply asking an MLLM to generate code from a chart image directly often leads to suboptimal results, with charts that are visually inaccurate or structurally flawed. This paper aims to bridge this gap by proposing a more robust and structured approach.
Methods
ChartIR tackles chart-to-code generation in two main stages:
- Initial Code Generation: This stage focuses on improving the initial understanding of the chart.
- Structured Instruction: Instead of just feeding the image, ChartIR first generates a detailed textual "description" of the chart's key visual elements (plot type, axes, colors, styles, annotations, etc.). For open-source models, they fine-tune a model (Qwen2.5-VL) on a dataset of chart descriptions.
- Combined Input: The MLLM then uses both the original chart image and this detailed description to generate an initial piece of code.
- Iterative Refinement: This stage progressively improves the generated code.
- Difference Generation: The code is executed to render a chart, which is then compared to the original reference chart. The MLLM is prompted to describe the "differences" between the two charts across various aspects (axes, colors, styles, text, grid, etc.).
- Iterative Updates: Using the original chart, the initial code, the difference description, and the chart description, the MLLM generates a new, refined version of the code. This process repeats, with each iteration aiming to reduce the visual discrepancy between the rendered chart and the reference chart. The refinement continues until convergence is reached or no further improvement is observed.
This approach is "training-free" and "model-agnostic," meaning it can be applied to various MLLMs without requiring additional training for each specific model.
Datasets
The paper evaluates ChartIR on two widely-used chart-to-code benchmarks:
- Plot2Code: Contains 132 manually curated test examples with diverse chart types, sizes, and elements.
- ChartMimic: Includes 500 triplets of (figure, code, instruction) for the Direct Mimic task, covering 18 regular and 4 advanced chart types.
The authors also created a dataset of approximately 5,000 (chart, description) pairs by prompting GPT-4o to generate descriptions for charts from the ChartX dataset, which was used for fine-tuning their open-source description model.
Key Insights and Ideas
- Decomposition is Key: Breaking down the complex chart-to-code task into distinct "visual understanding" (description) and "code translation" (generation/refinement) stages is crucial for better performance.
- Structured Instructions Matter: Simply providing an image isn't enough. Detailed, structured descriptions and explicit difference analysis guide the MLLM much more effectively than direct prompting.
- Iterative Refinement with Multi-dimensional Feedback: The iterative refinement process, informed by a comprehensive analysis of differences across multiple visual aspects (not just a single metric), leads to more robust and accurate code generation.
- Model Agnosticism is Achievable: The framework's ability to work with both open-source (Qwen2-VL) and closed-source (GPT-4o) models highlights its broad applicability.
Key Results
ChartIR consistently outperformed baseline methods (Direct Generation and METAL) across both open-source and closed-source models on the Plot2Code and ChartMimic datasets.
- GPT-4o: Achieved a GPT-40 Score of 6.56 on Plot2Code (17% improvement over direct generation) and 7.15 on ChartMimic, significantly outperforming METAL. It also showed improvements in low-level metrics like Text, Type, Layout, and Color.
- Qwen2-VL: Achieved a GPT-40 Score of 3.54 on Plot2Code (improvement from 3.12 direct) and 3.86 on ChartMimic, demonstrating substantial gains for open-source models.
- Ablation Studies: Removing either the "description" or "difference" component led to significant performance degradation, confirming the necessity of both parts of the ChartIR framework.
Limitations and Future Work
- Computational Cost: ChartIR requires more computational resources than simpler methods like direct prompting, although it uses fewer queries than METAL on closed-source models.
- Limited Impact on Advanced Models: For highly capable closed-source models like GPT-4o, the structured instructions have a relatively limited impact because the models already possess strong chart understanding. The authors suggest that future work could involve developing more powerful instruction generation models to further enhance performance on such models.
- Future Work: The authors envision ChartIR as a robust blueprint for future multimodal chart understanding and generation systems, suggesting further exploration into improving the instruction generation and refining the iterative process.
Summary updated