Last modified: Jun 14, 2025 By Alexander Williams
Install Plotly in Python for Interactive Visualizations
Plotly is a powerful library for creating interactive visualizations in Python. It supports charts, graphs, and dashboards. This guide will help you install Plotly quickly.
Table Of Contents
Prerequisites
Before installing Plotly, ensure you have Python installed. You can check this by running python --version
in your terminal.
python --version
If Python is not installed, download it from the official website. For other Python libraries, check our guide on Install Flask-SQLAlchemy in Python.
Install Plotly Using pip
The easiest way to install Plotly is using pip. Open your terminal and run the following command.
pip install plotly
This will download and install the latest version of Plotly. If you need a specific version, specify it like this.
pip install plotly==5.10.0
Verify the Installation
After installation, verify Plotly is working. Open a Python shell and import Plotly.
import plotly
print(plotly.__version__)
If no errors appear, Plotly is installed correctly. For troubleshooting, check our guide on Install PySpark in Python.
Create Your First Plot
Let’s create a simple interactive plot. Plotly Express is the easiest way to get started.
import plotly.express as px
# Sample data
data = px.data.iris()
# Create a scatter plot
fig = px.scatter(data, x="sepal_width", y="sepal_length", color="species")
# Show the plot
fig.show()
This code creates a scatter plot using the Iris dataset. The fig.show()
method displays the plot in your browser.
Save Plotly Charts
Plotly allows you to save charts as HTML or images. Use the write_html
or write_image
methods.
# Save as HTML
fig.write_html("plot.html")
# Save as PNG (requires kaleido)
fig.write_image("plot.png")
For write_image
, you may need to install Kaleido. Run pip install kaleido
if required.
Advanced Plotly Features
Plotly supports advanced features like animations and 3D plots. Here’s an example of a 3D scatter plot.
import plotly.express as px
# 3D scatter plot
fig = px.scatter_3d(px.data.iris(), x='sepal_length', y='sepal_width', z='petal_length', color='species')
fig.show()
For more complex workflows, check our guide on Install Dask in Python.
Conclusion
Plotly is a versatile library for interactive visualizations in Python. It’s easy to install and use. Follow this guide to start creating stunning charts today.
Key takeaways: Install Plotly using pip, verify the installation, and create your first plot. Explore advanced features for more dynamic visualizations.