Plotly in Python: Express Charts, Dash Apps, and the Version 7 Changes
Learn Plotly in Python with tested code: Plotly Express, graph objects, HTML and PNG export, Dash and Streamlit, plus what changed in plotly 7.

Learn Plotly in Python with tested code: Plotly Express, graph objects, HTML and PNG export, Dash and Streamlit, plus what changed in plotly 7.

Plotly is a Python library for interactive charts. Its getting started guide calls it "an interactive, open-source plotting library that supports over 40 unique chart types" covering statistical, financial, geographic, scientific, and 3-dimensional use cases. You hover, zoom, and filter in the browser, and the same figure object also exports to HTML or PNG.
The newest release is plotly 7.2.0, published on 24 November 2026, and the package logged 62,459,473 downloads in the last month as of 4 December 2026. Every code block in this guide ran on Python 3.15.2 with plotly 7.2.0, pandas 3.1.2, Dash 4.5.2, and Streamlit 1.68.0.
It goes from your first Plotly Express chart to graph objects, export, Dash and Streamlit apps, and the version 7 changes that break older tutorials.
px). The docs call it "the recommended starting point for creating most common figures," and every px function returns the same Figure object that graph objects build.go) when px cannot express the chart, such as a bar and a line on two y-axes. You can mix both on one figure.fig.write_html() keeps interactivity, but the default file inlines plotly.js and weighs about 4 MB. Pass include_plotlyjs="cdn" to get a file of a few kilobytes.fig.write_image() needs Kaleido 1.0.0 or later plus Chrome or Chromium, because plotly 7 removed Orca and older Kaleido support.px.scatter_mapbox() or ff.create_candlestick() fail on a current install.Plotly's Python library, often called plotly.py, builds charts as data. A figure is a tree of traces (the data to draw) and a layout (titles, axes, template), and the browser draws it with the JavaScript library plotly.js. That is why a Plotly chart can show tooltips and zoom without any JavaScript from you.
The company also sells hosted products, but the library itself is free. The package is MIT licensed on PyPI, and so are Dash and Kaleido.

If you know Matplotlib, think of Plotly as the interactive counterpart. Our Matplotlib guide covers static, publication-style charts, and our seaborn guide covers statistical plots on top of it. Plotly sits beside them for charts people will explore.
Plotly is the charting library behind Dash, which installs Plotly's graphing library with it. Dash alone logged 8,259,430 downloads in the same month, and Streamlit can render a Plotly figure with one call.
The release picture matters if you install it today. Plotly 7.0.0 shipped on 25 August 2026 and moved the bundled plotly.js from version 3 to version 4. It was followed by 7.1.0 and 7.2.0, so any tutorial older than late August 2026 was written for version 6 or earlier.
Three ideas explain most Plotly code: install the right extras, know that every chart is a Figure, and pick between Express and graph objects.
python -m venv .venv
source .venv/bin/activate
pip install -q plotly==7.2.0 pandas==3.1.2 numpy==2.5.5 kaleido==1.5.2 dash==4.5.2 streamlit==1.68.0
python -c "import plotly, pandas; print(plotly.__version__, pandas.__version__)"7.2.0 3.1.2The getting started page installs with pip install plotly, and says that for Plotly Express "you'll also need to install a supported dataframe library." PyPI lists plotly 7.2.0 as requiring Python 3.10 or newer. The pinned NumPy 2.5.5 needs Python 3.12 or newer, so this exact set needs Python 3.12 or newer.
In JupyterLab you also need jupyterlab and anywidget in the same environment, and the classic notebook needs notebook>=7.0 and anywidget>=0.9.13. Our Jupyter Notebook guide covers the setup, and our uv guide shows uv as an alternative to venv and pip.
import plotly.express as px
df = px.data.gapminder()
print(df.shape)
print(df.columns.tolist())
recent = df.query("year == 2007")
fig = px.scatter(
recent,
x="gdpPercap",
y="lifeExp",
size="pop",
color="continent",
hover_name="country",
log_x=True,
title="Life expectancy vs GDP per capita, 2007",
)
print(type(fig).__name__)
print([trace.name for trace in fig.data])
fig.write_html("scatter.html", include_plotlyjs="cdn")(1704, 8)
['country', 'continent', 'year', 'lifeExp', 'pop', 'gdpPercap', 'iso_alpha', 'iso_num']
Figure
['Asia', 'Europe', 'Africa', 'Americas', 'Oceania']px.data.gapminder() ships inside plotly, so it needs no download. One call turned 142 country rows for 2007 into a bubble chart with one trace per continent, and hover_name="country" labels each tooltip. Open scatter.html in a browser to hover and zoom.

In a script, fig.show() opens the chart in your browser. In a notebook it renders inline.
The Plotly Express page says every px function "uses graph objects internally and returns a plotly.graph_objects.Figure instance." Any px figure could be built with graph objects "with between 5 and 100 times more code." Express has more than 30 functions such as scatter, bar, histogram, box, treemap, and scatter_3d.
Because both return a Figure, you can start in Express and edit the result with graph-object methods.
import plotly.express as px
df = px.data.gapminder().query("country == 'Canada'")
fig = px.line(df, x="year", y="lifeExp", markers=True)
fig.update_traces(line_color="#d62728", name="Canada")
fig.update_layout(title="Canada: life expectancy", yaxis_title="Years", template="plotly_white")
print(fig.data[0].line.color, fig.layout.template.layout.paper_bgcolor)
print(sorted(fig.to_dict()))#d62728 white
['data', 'layout']update_traces() changes every trace at once and update_layout() changes titles, axes, and the template. The creating and updating figures guide describes the same pattern, and the final line shows what a figure is underneath: a dictionary with data and layout.
Four patterns cover most real work: a wide table, two measures on one chart, a grid of subplots, and a chart that stays fast with many points.
import pandas as pd
import plotly.express as px
wide = pd.DataFrame(
{
"month": ["Jan", "Feb", "Mar", "Apr"],
"free": [120, 135, 160, 172],
"pro": [30, 34, 41, 47],
"team": [8, 9, 12, 15],
}
)
fig = px.line(wide, x="month", y=["free", "pro", "team"], markers=True)
print([trace.name for trace in fig.data])
print(fig.data[0].hovertemplate)['free', 'pro', 'team']
variable=free<br>month=%{x}<br>value=%{y}<extra></extra>Passing a list to y made one line per column, and Express named the pivoted columns variable and value in the tooltip. The px arguments guide says px functions accept data in "long, wide, and mixed" formats, so you do not need melt() first. Rename the axis labels with labels={"variable": "plan", "value": "signups"} when the defaults read badly.
import plotly.express as px
import plotly.graph_objects as go
df = px.data.gapminder().query("country == 'Canada'")
fig = go.Figure()
fig.add_trace(go.Bar(x=df["year"], y=df["pop"], name="Population"))
fig.add_trace(
go.Scatter(x=df["year"], y=df["lifeExp"], name="Life expectancy", yaxis="y2", mode="lines+markers")
)
fig.update_layout(
title="Canada: population and life expectancy",
yaxis=dict(title="Population"),
yaxis2=dict(title="Life expectancy (years)", overlaying="y", side="right"),
)
print(len(fig.data), [trace.type for trace in fig.data])
print(fig.layout.yaxis2.overlaying, fig.layout.yaxis2.side)2 ['bar', 'scatter']
y rightThis is where graph objects earn their place: a bar trace and a line trace share one figure, and overlaying="y" puts the second y-axis on top of the first.
Plotly 7 changes how that second axis draws: the migration guide says an axis that overlays another now defaults to tickmode="sync", so both axes share one gridline set. Set tickmode="auto" on the overlaying axis to get the old independent grids.
import plotly.express as px
import plotly.graph_objects as go
from plotly.subplots import make_subplots
df = px.data.gapminder().query("year == 2007")
top = df.nlargest(8, "pop").sort_values("pop")
fig = make_subplots(rows=1, cols=2, subplot_titles=("Population", "Life expectancy"))
fig.add_trace(go.Bar(x=top["pop"], y=top["country"], orientation="h"), row=1, col=1)
fig.add_trace(go.Bar(x=top["lifeExp"], y=top["country"], orientation="h"), row=1, col=2)
fig.update_layout(template="plotly_white", showlegend=False, height=420)
fig.update_yaxes(showticklabels=False, row=1, col=2)
print(len(fig.data))
print(top[["country", "pop"]].tail(3).to_string(index=False))2
country pop
United States 301139947
India 1110396331
China 1318683096make_subplots() creates the grid, and the row and col arguments place each trace. The Plotly templates are named styles you apply with template=, and this install ships plotly, plotly_white, plotly_dark, ggplot2, seaborn, simple_white, and a few more. Set pio.templates.default = "plotly_white" once to change every chart in a session.
import numpy as np
import pandas as pd
import plotly.express as px
rng = np.random.default_rng(7)
for n in (1000, 1001):
data = pd.DataFrame({"x": rng.normal(size=n), "y": rng.normal(size=n)})
auto = px.scatter(data, x="x", y="y").data[0].type
svg = px.scatter(data, x="x", y="y", render_mode="svg").data[0].type
print(n, auto, svg)1000 scatter scatter
1001 scattergl scatterThe static export docs explain the switch: Plotly Express scatter charts with more than 1,000 points use WebGL by default (render_mode="auto"). WebGL draws many points quickly, but a vector export such as SVG or PDF then includes "encapsulated rasters" for those traces. Pass render_mode="svg" when you need fully vector output and can accept slower rendering.
Plotly figures leave Python in three ways: interactive HTML, static images, and a running app.
import os
import plotly.express as px
df = px.data.gapminder().query("year == 2007")
fig = px.bar(df.nlargest(5, "pop"), x="country", y="pop")
fig.write_html("full.html", include_plotlyjs=True)
fig.write_html("cdn.html", include_plotlyjs="cdn")
print(os.path.getsize("full.html") // 1_000_000, "MB inline")
print(os.path.getsize("cdn.html") // 1_000, "KB with CDN")
fig.write_image("top5.png", width=900, height=500, scale=2)
print(os.path.getsize("top5.png") > 10_000)4 MB inline
8 KB with CDN
TrueThe HTML export guide warns that the default self-contained file is "very large (5Mb+)" because it inlines plotly.js. Our measurement was about 4 MB, so treat the docs figure as a rough size, and note that include_plotlyjs="cdn" needs the reader to be online.
The static image export page requires Kaleido 1.0.0 or later and says Kaleido "uses Chrome for static image generation," which is no longer bundled. Install Chrome yourself, or run plotly_get_chrome or plotly.io.get_chrome(). write_image() then writes PNG, JPEG, WebP, SVG, and PDF.
The 7.0.0 release notes removed support for Kaleido versions below 1.0.0 and for Orca, and removed the engine argument from write_image(), to_image(), and pio.write_images(). Old snippets such as fig.write_image("a.png", engine="orca") now fail, and the fix is to delete the argument and install Kaleido 1.x.
When a chart needs inputs, put it in an app. Plotly's own framework is Dash, and Streamlit is the common alternative.
# app.py
from dash import Dash, dcc, callback, Output, Input
import plotly.express as px
df = px.data.gapminder()
app = Dash(__name__)
app.layout = [
dcc.Dropdown(sorted(df["country"].unique()), "Canada", id="country"),
dcc.Graph(id="pop-graph"),
]
@callback(Output("pop-graph", "figure"), Input("country", "value"))
def update(country):
return px.line(df[df["country"] == country], x="year", y="pop")
if __name__ == "__main__":
app.run(port=8051)Run it with python app.py and open the printed address.
The Dash installation page notes that pip install dash also installs plotly. The minimal app page uses the same pattern: a layout, a dcc.Graph, and a @callback that rebuilds the figure when the dropdown changes. A list as app.layout needs Dash 2.17.0 or later.
You can test the callback without a browser by using the Flask test client that Dash exposes as app.server.
from app import app
client = app.server.test_client()
print(client.get("/_dash-layout").status_code)
payload = {
"output": "pop-graph.figure",
"outputs": {"id": "pop-graph", "property": "figure"},
"inputs": [{"id": "country", "property": "value", "value": "Spain"}],
"changedPropIds": ["country.value"],
}
response = client.post("/_dash-update-component", json=payload)
figure = response.get_json()["response"]["pop-graph"]["figure"]
print(response.status_code, figure["data"][0]["type"], figure["layout"]["yaxis"]["title"]["text"])200
200 scatter popThe second request is what the browser sends when you pick Spain, and the response holds a line figure for the pop column. The Dash docs flag the built-in server as a development server, so use a production WSGI server when you deploy.
# st_app.py
import plotly.express as px
import streamlit as st
df = px.data.gapminder()
country = st.selectbox("Country", sorted(df["country"].unique()), index=0)
fig = px.line(df[df["country"] == country], x="year", y="lifeExp", title=country)
st.plotly_chart(fig, width="stretch")Run it with streamlit run st_app.py.
The st.plotly_chart docs require plotly>=4.0.0, and Streamlit offers pip install streamlit[charts] for its charting dependencies.
The same page gives a decision rule. For new 2D charts, "prefer a Vega-based chart command" such as st.line_chart. Use st.plotly_chart "for 3D charts, scientific chart types such as violin or ternary plots, or a Plotly figure you already have."
Streamlit ships a test harness, so you can check the app without opening it.
from streamlit.testing.v1 import AppTest
at = AppTest.from_file("st_app.py").run(timeout=60)
print(len(at.get("plotly_chart")))
at.selectbox[0].select("Spain").run()
spec = at.get("plotly_chart")[0].proto.spec
print(at.selectbox[0].value, '"Spain"' in spec)1
Spain TrueThe app rendered one Plotly chart, and after the selectbox changed to Spain the chart's title carried the new value. Streamlit may log a missing ScriptRunContext warning in bare mode, which you can ignore.
Version 7 is the first major release in a while, and it removes code that older tutorials still use. The migration guide lists every change. These are the ones most likely to bite.
import plotly.express as px
import plotly.figure_factory as ff
import plotly.graph_objects as go
print("px.scatter_mapbox:", hasattr(px, "scatter_mapbox"), "| px.scatter_map:", hasattr(px, "scatter_map"))
print("go.Scattermapbox:", hasattr(go, "Scattermapbox"), "| go.Scattermap:", hasattr(go, "Scattermap"))
print("ff.create_candlestick:", hasattr(ff, "create_candlestick"))px.scatter_mapbox: False | px.scatter_map: True
go.Scattermapbox: False | go.Scattermap: True
ff.create_candlestick: FalseThe Mapbox-based traces were deprecated in version 6 and are gone in 7, so replace px.scatter_mapbox with px.scatter_map and mapbox_style with map_style. The release notes also list 12 removed figure factories, including create_candlestick, create_gantt, create_ohlc, create_violin, and create_distplot, and the figure factories page lists the recommended alternatives.
Colors follow CSS Color 4 now, so "hsv(200, 80%, 80%)" and hex values without a leading # no longer work, and "rgb(0.5, 0.5, 0.5)" renders near black. Use "rgb(128, 128, 128)" or "#808080".
Map views fit to your data: layout.geo.fitbounds now defaults to "locations", so a map that plotted two countries zooms to them. Set fitbounds=False for the old world view. The migration guide also says showSendToCloud is enabled by default in version 7, which adds a "Share chart" button to the mode bar.
Plotly | Matplotlib | seaborn | |
|---|---|---|---|
How its docs describe it | "an interactive, open-source plotting library" | "a comprehensive library for creating static, animated, and interactive visualizations" | "a high-level interface for drawing attractive and informative statistical graphics" |
What draws the chart | plotly.js in the browser | Matplotlib's own renderers | Matplotlib |
Static image export |
|
| Through Matplotlib |
App frameworks | Dash, or | Embeds in apps | Through Matplotlib |
Large scatter plots | WebGL above 1,000 points in Express | Not covered here | Not covered here |
Reddit shows the trade-off in practice. On Reddit, one commenter in r/datascience said Matplotlib can make great plots but is not fun to use and that Plotly is better, while another poster noted Matplotlib renders animations much faster than Plotly.
Choose Plotly when readers will explore the chart or when it lives in an app. Choose Matplotlib or seaborn when the output is a static report or paper figure. They coexist: our Python data analysis guide covers the wider workflow, and our polars guide covers a faster DataFrame library, which Plotly Express supports through Narwhals.
Mapbox traces, figure factories, and Orca-based export all appear in older posts. Check the version that pip show plotly reports and the migration guide before debugging.
Kaleido 1.x does not bundle a browser. If write_image() fails, install Chrome or Chromium, or run plotly_get_chrome, instead of reinstalling Plotly.
A default write_html() inlines plotly.js into every file. Use include_plotlyjs="cdn" for charts you publish on the web, or "directory" to write one shared plotly.min.js beside the files.
Plotly Express labels pivoted columns variable and value. Pass labels={"variable": "plan", "value": "signups"} so tooltips and legends read well.
A scatter chart above 1,000 points becomes scattergl. Vector exports then rasterize those points, so set render_mode="svg" when you need clean vectors.

Learn seaborn with tested code: tidy data, axes-level vs figure-level plots, heatmaps, the objects API, and how 0.13.2 runs on pandas 3 and Matplotlib 3.11.

Learn Matplotlib the way its docs suggest: the Axes API, subplots, styles that don't look dated, and tested 3.11.2 code for the changes that break old snippets.

DuckDB vs SQLite tested in Python 3.15.2 on 1,000,000 rows: one wins aggregates by about 100x, the other wins lookups and inserts. Code and verdict inside.