Abstract
Multi-modal Large Language Models (MLLMs) have demonstrated impressive capabilities in visual understanding and reasoning. However, their ability to perform "visual coding"—the reverse-engineering of scientific plots into executable code—remains largely unexplored. This paper introduces Plot2Code, a benchmark consisting of 368 high-quality plots across various libraries (Matplotlib, Plotly) and languages (Python, R). We evaluate 14 MLLMs using a novel multi-metric approach, including a GPT-4V-based visual similarity judge. Our results reveal a significant performance gap between proprietary models like GPT-4V and open-source alternatives, particularly in complex tasks involving subplots and dense annotations.
Introduction
While MLLMs have become adept at describing images or answering questions about charts (ChartQA), their ability to generate the underlying code for a visual figure is a high-order reasoning task that is largely underexplored. To succeed in this "visual coding" task, a model must perceive fine-grained visual details, reason about data structures, and synthesize executable code. As noted by the authors, echoing Richard Feynman: "What I cannot create, I do not understand." If a model cannot recreate a plot, it likely lacks a full comprehension of the relationship between data and its visual representation.
Methodology
The researchers introduced the Plot2Code benchmark, which consists of 368 high-quality plots paired with their source code and descriptive instructions. The dataset covers Matplotlib (Python), Plotly (Python), and Plotly (R) across six categories, including Contours, Statistics, and Subplots.
The evaluation involves two primary settings:
- Direct Asking: The model receives only the image and must generate the code.
- Conditional Asking: The model receives the image plus a text-based description of the plot's requirements to simulate user instructions.
To assess performance, the authors propose a three-metric suite: Code Pass Rate (executability), Text-Match Ratio (OCR-based label accuracy), and a GPT-4V Rating Judgement (visual similarity on a 1–10 scale).
Key Insights and Results
The study reveals several critical findings regarding the current state of MLLMs:
- Proprietary Dominance: GPT-4V, Claude-3-Opus, and Gemini-1.5-Pro are the clear leaders. GPT-4V achieved the highest overall rating of 7.83/10 in the conditional setting, while open-source models like Mini-Gemini-8x7B-HD lagged behind at 6.08.
- Complexity and Spatial Reasoning: Performance varied significantly by plot type. While models handled simple bar charts well, they struggled with complex layouts. Spatial reasoning in "Subplots" and "Text, Labels & Annotations" proved to be a major bottleneck.
- The Instruction Paradox: Interestingly, adding text instructions (Conditional Asking) often decreased the code pass rate for some models. This suggests that while instructions clarify the goal, the added constraints increase coding complexity and the likelihood of syntax errors.
- Vision as the Bottleneck: Performance improved when models were provided with OCR tokens as text input, indicating that current vision encoders struggle to perceive small text elements in dense scientific plots.
Conclusion
Plot2Code highlights that visual coding remains a major frontier for AI reasoning. While proprietary models show promise, there is a significant gap in the open-source ecosystem. Future work should focus on improving visual perception for dense data and exploring advanced multi-modal prompting strategies, such as Chain-of-Thought for vision, to bridge the gap between perception and code generation.
Summary updated