V is C oder: Fine-Tuning LLM s for Executable Python Visualization Code Generation (2025)

Abstract: Large language models (LLMs) often struggle with visualization tasks like plotting diagrams, charts, where success depends on both code correctness and visual semantics. Existing instruction-tuning datasets lack execution-grounded supervision and offer limited support for iterative code correction, resulting in fragile and unreliable plot generation. We present **VisCode-200K**, a large-scale instruction tuning dataset for Python-based visualization and self-correction. It contains over 200K examples from two sources: (1) validated plotting code from open-source repositories, paired with natural language instructions and rendered plots; and (2) 45K multi-turn correction dialogues from Code-Feedback, enabling models to revise faulty code using runtime feedback. We fine-tune Qwen2.5-Coder-Instruct on VisCode-200K to create **VisCoder**, and evaluate it on PandasPlotBench. VisCoder significantly outperforms strong open-source baselines and approaches the performance of proprietary models like GPT-4o-mini. We further adopt a self-debug evaluation protocol to assess iterative repair, demonstrating the benefits of feedback-driven learning for executable, visually accurate code generation.

## introduction despite the growing capabilities of large language models (llms) in general-purpose code generation @xcite , they continue to struggle with one of the most common and visually essential tasks in data analysis: generating code that produces a valid and semantically meaningful plot. for example, given a tabular description, models may generate code that appears syntactically correct and invokes the appropriate libraries @xcite . but when executed, the result is often broken: exceptions are raised, plots render blank or malformed, or the visual fails to reflect the intended semantics of the instruction @xcite @xcite . these failures are not incidental: they reflect structural challenges in visualization code generation. unlike standard text-to-code tasks, visualization requires grounding across three modalities: natural language (the user instruction), data structure (the tabular or other data input), and visual output (the rendered chart). execution correctness is not binary; a script may run and still fail to convey the intended meaning. visualization libraries such as matplotlib @xcite , seaborn @xcite , and plotly (inc, 2015) further complicate the task, with api idiosyncrasies and intricate bindings between data, layout, and style. current instruction-tuning datasets do not meet the demands of this setting. most lack explicit visual grounding, do not enforce runtime validation, and provide little to no supervision for recovery from failure. as a result, even the most advanced open models like qwen-coder @xcite or @xcite struggle with executable, semantically accurate visualization code, particularly when debugging is required @xcite . to address these gaps, we introduce viscode-200k, a new instruction-tuning dataset for pythonbased visualization code generation and multi-turn correction. viscode-200k contains over 200k supervised examples derived from two complementary data sources: 1) executable visualization code, extracted from open-source python repositories and filtered across widely-used plotting libraries, including matplotlib, seaborn and others. all code samples are validated for runtime executability and paired with rendered plots. natural language instructions are generated using llms conditioned on both the code and its output image @xcite . 2) multi-turn revision dialogues, drawn from the code-feedback dataset @xcite , which contains re-alistic interactions where models revise faulty python code based on runtime errors and follow-up prompts. while not visualization-specific, these traces provide essential supervision for teaching models to debug and recover from execution failures. this dual-source construction enables training for both single-shot generation and multi-round refinement, allowing models to generate code initially and improve it iteratively through feedback. to demonstrate the effectiveness of viscode-200k, we fine-tune qwen2.5-coder-instruct @xcite at both 3b and 7b scales to produce viscoder, an open-source model tuned specifically for python visualization tasks. we evaluate vis-coder on pandasplotbench @xcite , a benchmark that assesses executable code generation from natural language and data previews across three plotting libraries. we also introduce a self-debug evaluation mode, in which models are given multiple rounds to revise failed outputs based on execution traces, simulating a realistic developer-style correction loop. our experiments show that viscoder substantially outperforms competitive open-source baselines. viscoder-3b and 7b achieve average execution pass rate improvements of 19.6 and 14.5 points over qwen2.5-coder. under self-debug mode, it reaches over 90% execution pass rate on matplotlib and seaborn. compared to proprietary models, viscoder-7b surpasses gpt-4o-mini on both seaborn and plotly under the default setting, and approaches gpt-4o performance on both libraries after self-debugging. at 3b scale, it outperforms gpt-4o-mini on seaborn and narrows the gap in other libraries. these results demonstrate the impact of combining domain-specific instruction tuning with feedback-driven correction for grounded visualization code generation. execution feedback and code correction. execution feedback has been widely explored as a supervisory signal for improving the reliability of code generation. prior work investigates using runtime traces to guide post-hoc refinement @xcite @xcite , or integrates such signals into training through reinforcement learning @xcite . other approaches emphasize multi-turn correction, where models revise faulty code using internal or external feedback @xcite @xcite , or simulate debugging workflows with planning and agent collaboration @xcite . in the context of visualization, vispath @xcite and matplotagent @xcite explore chart refinement using visual feedback from rendered outputs. yet despite these advances, supervision grounded in execution feedback or revision traces has rarely been used to train models for visualization code generation, where runtime validity and semantic alignment remain central challenges. data filtering 1 runtime validation 2 instruction gen. 3 filtered code block runnable vis code & image nbconvert --allow-errors false gen. images validation code data python vis code block libs filter code block extraction libs filter matplotlib, seaborn, ploty python vis code + image viscode-200k split 5 parts desc. construct instruction merge code-feedback ## viscode-200k: a python visualization instruction tuning dataset in this section, we present viscode-200k, a supervised instruction tuning dataset for python-based visualization and feedback-driven code correction. it is designed to support robust code generation across diverse plotting libraries and to enable iterative refinement through multi-turn supervision. viscode-200k integrates two complementary sources of supervision. the first consists of executable visualization code extracted from opensource python repositories, covering a wide range of real-world chart types, layouts, and plotting libraries. all samples are filtered to ensure runtime validity and compatibility with standard python environments, exposing models to diverse and realistic plotting practices. the second source comprises multi-turn python dialogues from the code-feedback dataset @xcite , which offer supervision for revising faulty code in response to execution errors. while not specific to visualization, these interactions are critical for modeling realistic correction behaviors in iterative workflows. figure 1 provides an overview of the viscode-200k construction pipeline, which consists of code filtering, runtime validation, and structured instruction generation. the following subsections detail each component. ## experiment setup training setup. we fine-tune qwen2.5-coder-instruct @xcite at two parameter scales: 3b and 7b. this allows us to assess the generalizability of viscode-200k across different model capacities. both models are trained for 3 epochs with a learning rate of 5 × 10 -6 , a warm-up ratio of 0.05, and a cosine learning rate scheduler. we perform full-parameter tuning in bfloat16 precision on 8×a100 gpus with a total batch size of 128, using swift infrastructure @xcite . evaluation setup. we evaluate models using pandasplotbench @xcite , a benchmark designed to assess the ability of language models to generate executable and semantically accurate visualization code from tabular data descriptions. it contains 175 tasks spanning three widely used python plotting libraries: matplotlib, seaborn, and plotly. each task includes a natural language instruction and a preview of the input dataframe. the model is expected to generate python code that produces a valid plot when executed according to the instruction. the benchmark reports three metrics: (1) incorrect code rate, the proportion of outputs that fail to produce any plot; and two gpt-4o-judged scores: (2) a task-based score measuring alignment with the instruction, and (3) a visual score assessing similarity to the reference plot. among these metrics, incorrect code rate provides only a coarse signal of success. it indicates whether a plot is rendered, but does not capture execution errors if a figure is produced. as a result, blank or semantically meaningless outputs-such as plots with only axes-may be misclassified as correct. to address this issue, we introduce an additional metric: execution pass rate, defined as the percentage of outputs that execute without error. ## main results we present the main experimental results on pan-dasplotbench, including overall model comparisons, performance under the self-debug evaluation protocol, error type analysis, and a training data ablation study. more detailed results are provided in appendix d. ## conclusion in conclusion, viscode-200k provides a largescale instruction tuning dataset for python visualization code generation, combining executable plotting examples with multi-turn correction dialogues grounded in runtime feedback. to validate its effectiveness, we evaluate viscoder models on pandasplotbench using the default setting. additionally, we propose a self-debug protocol to simulate realistic correction workflows and assess model performance in this extended evaluation mode. experiments show that viscoder substantially outperforms strong open-source baselines across execution and alignment metrics, and narrows the gap to proprietary models like gpt-4o-mini. gains are particularly pronounced in settings that involve complex visualization structures, such as plotly, and iterative correction through selfdebugging. ablation studies further demonstrate that structurally diverse, executable training data and feedback-driven supervision contribute to more robust performance across plotting libraries. looking forward, this work reinforces the importance of domain-specific instruction tuning and multi-turn correction supervision for building robust and semantically grounded visualizationcapable models. future extensions may explore broader plotting libraries, richer correction supervision, and evaluation methods that measure models' abilities to recover from execution errors.