Skip to main content

Plot Agent

Tests PyPI version

An AI-powered data visualization assistant that helps users create Plotly visualizations in Python.

Built on LangGraph with tool-calling to reliably execute generated Plotly code in a sandbox and keep the current fig in sync.

Installation

You can install the package using pip:

pip install plot-agent

Usage

See more examples in /examples/ (via nbviewer so that can see the charts easily).

Here's a simple minimal example of how to use Plot Agent:

import pandas as pd
from plot_agent.agent import PlotAgent

# ensure OPENAI_API_KEY is set (env or .env); optional debug via PLOT_AGENT_DEBUG=1

# Create a sample dataframe
df = pd.DataFrame({
    'x': [1, 2, 3, 4, 5],
    'y': [10, 20, 30, 40, 50]
})

# Initialize the agent
agent = PlotAgent()

# Set the dataframe
agent.set_df(df)

# Process a visualization request
response = agent.process_message("Create a line plot of x vs y")

# Print generated code
print(agent.generated_code)

# Get fig
fig = agent.get_figure()
fig.show()

agent.generated_code:

import pandas as pd
import plotly.graph_objects as go

# Creating a line plot of x vs y
# Create a figure object
fig = go.Figure()

# Add a line trace to the figure
fig.add_trace(
    go.Scatter(
        x=df['x'],  # The x values
        y=df['y'],  # The y values
        mode='lines+markers',  # Display both lines and markers
        name='Line Plot',  # Name of the trace
        line=dict(color='blue', width=2)  # Specify line color and width
    )
)

# Adding titles and labels
fig.update_layout(
    title='Line Plot of x vs y',  # Plot title
    xaxis_title='x',  # x-axis label
    yaxis_title='y',  # y-axis label
    template='plotly_white'  # A clean layout
)

How it works

flowchart TD
    A[User message] --> B{LangGraph ReAct Agent}
    subgraph Tools
      T1[execute_plotly_code<br/>- runs code in sandbox<br/>- returns success/fig/error]
      T2[does_fig_exist]
      T3[view_generated_code]
    end
    B -- tool call --> T1
    T1 -- result --> B
    B -- optional --> T2
    B -- optional --> T3
    B --> C[AI response]
    C --> D{Agent wrapper}
    D -- persist messages --> B
    D -- extract code blocks --> E[Sandbox execution]
    E --> F[fig]
    F --> G[get_figure]
  • The LangGraph agent plans and decides when to call tools.
  • The wrapper persists full graph messages between turns and executes any returned code blocks to keep fig updated.
  • A safe execution environment runs code with an allowlist and a main-thread-only timeout.

Features

  • AI-powered visualization generation
  • Support for various Plotly chart types
  • Automatic data preprocessing
  • Interactive visualization capabilities
  • LangGraph-based tool calling and control flow
  • Debug logging via PlotAgent(debug=True) or PLOT_AGENT_DEBUG=1

Requirements

  • Python 3.8 or higher
  • Dependencies are automatically installed with the package

Development

  • Run unit tests:
make test
  • Execute all example notebooks:
make run-examples
  • Execute with debug logs enabled:
make run-examples-debug
  • Quick CLI repro that prints evolving code each step:
make run-example-script

License

This project is licensed under the MIT License - see the LICENSE file for details.

Metadata

Release files for plot-agent 0.5.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for plot-agent 0.5.1
File Size Uploaded Provenance
plot_agent-0.5.1.tar.gz 16.1 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for plot-agent 0.5.1
File Interpreter ABI Platform
plot_agent-0.5.1-py3-none-any.whl Python 3 none any Details

Total release size: 32.3 kB

Release files / plot_agent-0.5.1.tar.gz

Download URL plot_agent-0.5.1.tar.gz
Size 16.1 kB
Tags Source
SHA-256 checksum
How to use checksums
796a39f1284cf26bba38ef1a75e07c520edf2a29e51991c4aadd16ffb51a93f1
BLAKE2b-256 checksum
How to use checksums
45a06f955fa1ebdf5794b14ef5be2f1350d8671e094354c928971d756f327bdd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 4, 2026.

Transparency log

Release files / plot_agent-0.5.1-py3-none-any.whl

Download URL plot_agent-0.5.1-py3-none-any.whl
Size 16.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
14561673362a05d3bf2ef5f71c64d913925749639cdb587388d9e3c2fb64f317
BLAKE2b-256 checksum
How to use checksums
e410620b9033564f4c70f9f404e6a95b533e584c5de15b2d1d60a7d9a0a237f1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 4, 2026.

Transparency log

Security for plot-agent 0.5.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for plot_agent-0.5.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 4, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page