Introduction to Plotly Express
Why Plotly?
Plotly charts are interactive:
- Hover tooltips
- Zoom and pan
- Legend toggling
This makes Plotly great for:
- Exploratory analysis
- Sharing insights in a browser
- Lightweight dashboards
Plotly Express vs Graph Objects
- plotly.express (px): high-level, quick charts (recommended to start)
- plotly.graph_objects: low-level building blocks (more control)
This phase focuses on Plotly Express.
First interactive chart
Plotly Express line chart
import pandas as pd
import plotly.express as px
df = pd.DataFrame({
"day": [1, 2, 3, 4, 5],
"orders": [120, 140, 130, 160, 155],
})
fig = px.line(df, x="day", y="orders", title="Orders over time")
fig.show()Plotly Express line chart
import pandas as pd
import plotly.express as px
df = pd.DataFrame({
"day": [1, 2, 3, 4, 5],
"orders": [120, 140, 130, 160, 155],
})
fig = px.line(df, x="day", y="orders", title="Orders over time")
fig.show()Saving/exporting
You can export:
- HTML (best for interactive sharing)
- PNG (static)
Save to HTML
# fig.write_html("orders.html")Save to HTML
# fig.write_html("orders.html")PNG export may require extra dependencies (kaleido).
If this helped you, consider buying me a coffee ☕
Buy me a coffeeWas this page helpful?
Let us know how we did
