You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An AI-powered data visualization assistant that helps users create Plotly visualizations in Python.
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:
importpandasaspdfromplot_agent.agentimportPlotAgent# ensure OPENAI_API_KEY is set and available for langchain# Create a sample dataframedf=pd.DataFrame({
'x': [1, 2, 3, 4, 5],
'y': [10, 20, 30, 40, 50]
})
# Initialize the agentagent=PlotAgent()
# Set the dataframeagent.set_df(df)
# Process a visualization requestresponse=agent.process_message("Create a line plot of x vs y")
# Print generated codeprint(agent.generated_code)
# Get figfig=agent.get_figure()
fig.show()
agent.generated_code:
importpandasaspdimportplotly.graph_objectsasgo# Creating a line plot of x vs y# Create a figure objectfig=go.Figure()
# Add a line trace to the figurefig.add_trace(
go.Scatter(
x=df['x'], # The x valuesy=df['y'], # The y valuesmode='lines+markers', # Display both lines and markersname='Line Plot', # Name of the traceline=dict(color='blue', width=2) # Specify line color and width
)
)
# Adding titles and labelsfig.update_layout(
title='Line Plot of x vs y', # Plot titlexaxis_title='x', # x-axis labelyaxis_title='y', # y-axis labeltemplate='plotly_white'# A clean layout
)
Features
AI-powered visualization generation
Support for various Plotly chart types
Automatic data preprocessing
Interactive visualization capabilities
Integration with LangChain for advanced AI capabilities
Requirements
Python 3.8 or higher
Dependencies are automatically installed with the package
License
This project is licensed under the MIT License - see the LICENSE file for details.
About
PlotAgent().set_df(df).process_message("plot this df in the best way you can think of").get_figure().show()