Plotly & Interactive Charts
Static charts are great for reports, but sometimes you need interactivity. Plotly creates charts you can hover over, zoom into, and filter. They're perfect for dashboards and web applications.
Your First Interactive Chart
Plotly Express is the high-level interface that makes interactive charts as easy as seaborn. The output is a browser-ready HTML chart.
import plotly.express as px
df = px.data.gapminder()
fig = px.scatter(df, x="gdpPercap", y="lifeExp",
size="pop", color="continent",
hover_name="country",
title="Life Expectancy vs GDP")
fig.show()
Hover over any point to see details. Zoom with your mouse. Click legend items to filter. This interactivity makes exploratory analysis much richer.
Try it Yourself →Common Plotly Charts
Plotly Express supports all the standard chart types plus some unique ones like animated charts.
import plotly.express as px
import pandas as pd
df = pd.DataFrame({
"month": ["Jan", "Feb", "Mar", "Apr"],
"sales": [100, 150, 130, 170]
})
fig = px.bar(df, x="month", y="sales", title="Monthly Sales")
fig.show()
fig2 = px.line(df, x="month", y="sales", title="Sales Trend")
fig2.show()
The syntax is identical regardless of chart type — just change px.bar to px.line or px.scatter. Plotly handles the rest.
Animated Charts
This is where Plotly really shines. You can animate data over time to show trends dynamically.
import plotly.express as px
df = px.data.gapminder()
fig = px.animation_gapminder(
x="gdpPercap", y="lifeExp",
size="pop", color="continent",
hover_name="country",
log_x=True, size_max=55,
range_x=[100, 100000],
range_y=[25, 90],
animation_frame="year"
)
fig.show()
The animation_frame parameter creates a time slider. This is incredibly effective for presentations and storytelling with data.
Key Takeaways
- Plotly creates interactive charts that work in browsers
- Plotly Express has a simple, consistent API across chart types
- Hover, zoom, and filtering come built-in
- Animation capabilities make it perfect for time-series storytelling