NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

VisCoder: Fine-Tuning LLMs for Executable Python Visualization Code Generation

Yuansheng Ni, Ping Nie, Kai Zou, Xiang Yue, Wenhu Chen

TL;DR

This paper introduces VisCode-200K, a large-scale dataset for generating executable Python visualization code, addressing the limitations of existing datasets in handling code correctness and visual semantics. They fine-tune LLMs on this dataset to create VisCoder, which significantly outperforms open-source baselines and approaches proprietary models, especially when incorporating iterative self-debugging.

What Problem Does This Paper Address?

Generating code that produces accurate and semantically meaningful visualizations is a surprisingly difficult task for Large Language Models (LLMs). While LLMs are good at general code generation, visualization code presents a unique challenge because it requires grounding across three modalities: natural language instructions, data structures, and the visual output (the plot itself). Existing instruction-tuning datasets often lack execution grounding, don't enforce runtime validation, and offer limited support for iterative code correction. This leads to models generating code that might run but produces incorrect or nonsensical plots, failing to capture the user's intent. This is particularly problematic for libraries like Plotly, which have complex APIs.

Methods

The core contribution is the VisCode-200K dataset, a novel instruction-tuning dataset for Python visualization code generation and multi-turn correction. It's built from two sources:

  1. Validated Plotting Code: Executable visualization code from open-source Python repositories, paired with natural language instructions and rendered plots. This code is validated for runtime executability.
  2. Multi-turn Correction Dialogues: Data from the Code-Feedback dataset, providing examples of how models can revise faulty code based on runtime errors and feedback.

The authors then fine-tune Qwen2.5-Coder-Instruct (a large language model) on VisCode-200K to create VisCoder. They also introduce a self-debug evaluation protocol where models are allowed multiple rounds to revise failed outputs based on execution traces, simulating a realistic developer workflow.

Datasets

  • VisCode-200K (New Dataset): A large-scale dataset (over 200K examples) for Python visualization code generation and self-correction. It combines:
  • Validated plotting code from open-source repositories (sourced from stack-edu and CoSyn-400K).
  • Multi-turn correction dialogues from the Code-Feedback dataset.
  • PandasPlotBench (Evaluation Benchmark): Used to evaluate VisCoder. It contains 175 tasks across Matplotlib, Seaborn, and Plotly, assessing executable code generation from natural language and data previews.
  • stack-edu: A source for educational Python code examples.
  • CoSyn-400K: A dataset containing synthetic plotting code.
  • Code-Feedback: A dataset of multi-turn Python dialogues for code correction.

Key Insights and Ideas

  • Visualization is Harder: The multi-modal nature of visualization (text, data, image) makes it inherently more complex for LLMs than standard code generation.
  • Execution Matters: Simply running code isn't enough; it needs to produce a correct and semantically meaningful plot. Runtime validation and execution feedback are crucial for training.
  • Iterative Refinement is Key: Models can significantly improve their performance by learning to debug and correct their own code through iterative feedback loops, mimicking how human developers work.
  • Data Diversity is Crucial: The VisCode-200K dataset's combination of real-world code, diverse plotting libraries, and multi-turn correction dialogues is essential for building robust visualization models. Datasets like CoSyn-400K alone, despite being synthetic, didn't generalize well due to their homogeneous structure.
  • Plotly is a Tough Nut to Crack: The verbose syntax and complex API of Plotly pose a greater challenge, leading to more semantic execution errors that are harder for models to resolve.

Key Results

  • VisCoder Outperforms Baselines: VisCoder models (3B and 7B scales) significantly outperform their untuned Qwen2.5-Coder baselines on the PandasPlotBench benchmark.
  • Approaching Proprietary Models: VisCoder-7B approaches the performance of proprietary models like GPT-40-mini, and even surpasses it on Seaborn and Plotly.
  • Self-Debug Boosts Performance: The self-debug evaluation protocol dramatically improves execution pass rates for all models, with VisCoder-7B reaching over 90% execution success on Matplotlib and Seaborn.
  • Error Type Analysis: VisCoder-7B shows strong recovery from structural errors (like AttributeError, TypeError) but struggles more with semantic errors (KeyError, ValueError), especially in Plotly.
  • Model Scale: VisCoder consistently shows performance gains across different model scales (1.5B to 14B), outperforming Qwen2.5-Coder baselines at each scale.
  • Baseline Extension: Fine-tuning other LLMs (DeepSeek-Coder, CodeLLaMA, StarCoder) on VisCode-200K also yields significant improvements, demonstrating the dataset's broad applicability.

Limitations and Future Work

  • Plotly Challenges: Performance on Plotly remains weaker compared to Matplotlib and Seaborn, with semantic execution errors being particularly difficult to resolve.
  • Evaluation Reliance: The evaluation relies on an automatic judge model, and the authors acknowledge the potential for biases in this model.
  • Limited Language Support: The current work is limited to Python, leaving visualization tasks in other languages (like R, JavaScript) unexplored.
  • Future Work: The authors suggest exploring broader plotting libraries, richer correction supervision, and developing evaluation methods that better capture models' abilities to recover from execution errors. They also plan to investigate the potential biases of the automatic judge model.

Summary updated

BibTeX
@inproceedings{ni2025viscoder,
  author = {Yuansheng Ni and Ping Nie and Kai Zou and Xiang Yue and Wenhu Chen},
  title = {{VisCoder: Fine-Tuning LLMs for Executable Python Visualization Code Generation}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2025},
}
Figure