Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.

Latest commit

History

History
269 lines (205 loc) · 7.74 KB

File metadata and controls

269 lines (205 loc) · 7.74 KB
jupyter
jupytextkernelspec
formatstext_representation
ipynb,md
extensionformat_nameformat_versionjupytext_version
.md
markdown
1.1
1.1.1
display_namelanguagename
Python 3
python
python3

Plotly Express Gallery

Plotly Express is a terse, consistent, high-level wrapper around Plotly.py for rapid data exploration and figure generation.

This notebook demonstrates various plotly_express features. Reference documentation and a step by step walkthrough notebook are also available.

You can also read our Medium announcement article for more information on this library.

A single import

importplotly_expressaspx

Built-in sample datasets

print(px.data.iris.__doc__)
iris=px.data.iris()
tips=px.data.tips()
gapminder=px.data.gapminder()
election=px.data.election()
wind=px.data.wind()
carshare=px.data.carshare()

Scatter and Line plots

px.scatter(iris, x="sepal_width", y="sepal_length")
px.scatter(iris, x="sepal_width", y="sepal_length", color="species")
px.scatter(iris, x="sepal_width", y="sepal_length", color="species", marginal_y="rug", marginal_x="histogram")
px.scatter(iris, x="sepal_width", y="sepal_length", color="species", marginal_y="violin",
marginal_x="box", trendline="ols")
iris["e"] =iris["sepal_width"]/100px.scatter(iris, x="sepal_width", y="sepal_length", color="species", error_x="e", error_y="e")
deliris["e"]
px.scatter(tips, x="total_bill", y="tip", facet_row="time", facet_col="day", color="smoker", trendline="ols",
category_orders={"day": ["Thur", "Fri", "Sat", "Sun"], "time": ["Lunch", "Dinner"]})
px.scatter_matrix(iris)
px.scatter_matrix(iris, dimensions=["sepal_width", "sepal_length", "petal_width", "petal_length"], color="species")
px.parallel_coordinates(iris, color="species_id", labels={"species_id": "Species",
"sepal_width": "Sepal Width", "sepal_length": "Sepal Length",
"petal_width": "Petal Width", "petal_length": "Petal Length", },
color_continuous_scale=px.colors.diverging.Tealrose, color_continuous_midpoint=2)
px.parallel_categories(tips, color="size", color_continuous_scale=px.colors.sequential.Inferno)
px.scatter(tips, x="total_bill", y="tip", color="size", facet_col="sex",
color_continuous_scale=px.colors.sequential.Viridis, render_mode="webgl")
px.scatter(gapminder.query("year==2007"), x="gdpPercap", y="lifeExp", size="pop", color="continent",
hover_name="country", log_x=True, size_max=60)
px.scatter(gapminder, x="gdpPercap", y="lifeExp", animation_frame="year", animation_group="country",
size="pop", color="continent", hover_name="country", facet_col="continent",
log_x=True, size_max=45, range_x=[100,100000], range_y=[25,90])
px.line(gapminder, x="year", y="lifeExp", color="continent", line_group="country", hover_name="country",
line_shape="spline", render_mode="svg")
px.area(gapminder, x="year", y="pop", color="continent", line_group="country")

Visualize Distributions

px.density_contour(iris, x="sepal_width", y="sepal_length")
px.density_contour(iris, x="sepal_width", y="sepal_length", color="species", marginal_x="rug", marginal_y="histogram")
px.density_heatmap(iris, x="sepal_width", y="sepal_length", marginal_x="rug", marginal_y="histogram")
px.bar(tips, x="sex", y="total_bill", color="smoker", barmode="group")
px.bar(tips, x="sex", y="total_bill", color="smoker", barmode="group", facet_row="time", facet_col="day",
category_orders={"day": ["Thur", "Fri", "Sat", "Sun"], "time": ["Lunch", "Dinner"]})
px.histogram(tips, x="total_bill", y="tip", color="sex", marginal="rug", hover_data=tips.columns)
px.histogram(tips, x="sex", y="tip", histfunc="avg", color="smoker", barmode="group",
facet_row="time", facet_col="day", category_orders={"day": ["Thur", "Fri", "Sat", "Sun"],
"time": ["Lunch", "Dinner"]})
px.strip(tips, x="total_bill", y="time", orientation="h", color="smoker")
px.box(tips, x="day", y="total_bill", color="smoker", notched=True)
px.violin(tips, y="tip", x="smoker", color="sex", box=True, points="all", hover_data=tips.columns)

Ternary Coordinates

px.scatter_ternary(election, a="Joly", b="Coderre", c="Bergeron", color="winner", size="total", hover_name="district",
size_max=15, color_discrete_map= {"Joly": "blue", "Bergeron": "green", "Coderre":"red"} )
px.line_ternary(election, a="Joly", b="Coderre", c="Bergeron", color="winner", line_dash="winner")

3D Coordinates

px.scatter_3d(election, x="Joly", y="Coderre", z="Bergeron", color="winner", size="total", hover_name="district",
symbol="result", color_discrete_map= {"Joly": "blue", "Bergeron": "green", "Coderre":"red"})
px.line_3d(election, x="Joly", y="Coderre", z="Bergeron", color="winner", line_dash="winner")

Polar Coordinates

px.scatter_polar(wind, r="frequency", theta="direction", color="strength", symbol="strength",
color_discrete_sequence=px.colors.sequential.Plasma[-2::-1])
px.line_polar(wind, r="frequency", theta="direction", color="strength", line_close=True,
color_discrete_sequence=px.colors.sequential.Plasma[-2::-1])
px.bar_polar(wind, r="frequency", theta="direction", color="strength", template="plotly_dark",
color_discrete_sequence=px.colors.sequential.Plasma[-2::-1])

Maps

px.set_mapbox_access_token(open(".mapbox_token").read())
px.scatter_mapbox(carshare, lat="centroid_lat", lon="centroid_lon", color="peak_hour", size="car_hours",
color_continuous_scale=px.colors.cyclical.IceFire, size_max=15, zoom=10)
px.set_mapbox_access_token(open(".mapbox_token").read())
px.line_mapbox(carshare, lat="centroid_lat", lon="centroid_lon", color="peak_hour")
px.scatter_geo(gapminder, locations="iso_alpha", color="continent", hover_name="country", size="pop",
animation_frame="year", projection="natural earth")
px.line_geo(gapminder.query("year==2007"), locations="iso_alpha", color="continent", projection="orthographic")
px.choropleth(gapminder, locations="iso_alpha", color="lifeExp", hover_name="country", animation_frame="year",
color_continuous_scale=px.colors.sequential.Plasma, range_color=[20,80])

Built-in Color Scales and Sequences (and a way to see them!)

px.colors.qualitative.swatches()
px.colors.sequential.swatches()
px.colors.diverging.swatches()
px.colors.cyclical.swatches()
px.colors.colorbrewer.swatches()
px.colors.cmocean.swatches()
px.colors.carto.swatches()

Next steps

Phew, you've made it this far! If you want to use Plotly Express yourself, just pip install plotly_express to install it and head on over to our reference documentation or just copy-paste from the examples above!

print(px.__version__)