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

Commit ec383e9

Browse files
migrate to jupytext
1 parent 5fb005b commit ec383e9

5 files changed

Lines changed: 399 additions & 128064 deletions

File tree

gallery.ipynb

Lines changed: 0 additions & 96942 deletions
This file was deleted.

gallery.md

Lines changed: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,253 @@
1+
---
2+
jupyter:
3+
jupytext:
4+
formats: ipynb,md
5+
text_representation:
6+
extension: .md
7+
format_name: markdown
8+
format_version: "1.1"
9+
jupytext_version: 1.1.1
10+
kernelspec:
11+
display_name: Python 3
12+
language: python
13+
name: python3
14+
---
15+
16+
# Plotly Express Gallery
17+
18+
Plotly Express is a terse, consistent, high-level wrapper around [Plotly.py](https://plot.ly/python) for rapid data exploration and figure generation.
19+
20+
This notebook demonstrates various `plotly_express` features. [Reference documentation](https://plotly.github.io/plotly_express/plotly_express/) and a [step by step walkthrough notebook](https://nbviewer.jupyter.org/github/plotly/plotly_express/blob/gh-pages/walkthrough.ipynb) are also available.
21+
22+
You can also read our [Medium announcement article](https://medium.com/@plotlygraphs/introducing-plotly-express-808df010143d) for more information on this library.
23+
24+
## A single import
25+
26+
```python
27+
import plotly_express as px
28+
```
29+
30+
## Built-in sample datasets
31+
32+
```python
33+
print(px.data.iris.__doc__)
34+
iris = px.data.iris()
35+
```
36+
37+
```python
38+
tips = px.data.tips()
39+
gapminder = px.data.gapminder()
40+
election = px.data.election()
41+
wind = px.data.wind()
42+
carshare = px.data.carshare()
43+
```
44+
45+
## Scatter and Line plots
46+
47+
```python
48+
px.scatter(iris, x="sepal_width", y="sepal_length")
49+
```
50+
51+
```python
52+
px.scatter(iris, x="sepal_width", y="sepal_length", color="species")
53+
```
54+
55+
```python
56+
px.scatter(iris, x="sepal_width", y="sepal_length", color="species", marginal_y="rug", marginal_x="histogram")
57+
```
58+
59+
```python
60+
px.scatter(iris, x="sepal_width", y="sepal_length", color="species", marginal_y="violin",
61+
marginal_x="box", trendline="ols")
62+
```
63+
64+
```python
65+
iris["e"] = iris["sepal_width"]/100
66+
px.scatter(iris, x="sepal_width", y="sepal_length", color="species", error_x="e", error_y="e")
67+
```
68+
69+
```python
70+
del iris["e"]
71+
```
72+
73+
```python
74+
px.scatter(tips, x="total_bill", y="tip", facet_row="time", facet_col="day", color="smoker", trendline="ols",
75+
category_orders={"day": ["Thur", "Fri", "Sat", "Sun"], "time": ["Lunch", "Dinner"]})
76+
```
77+
78+
```python
79+
px.scatter_matrix(iris)
80+
```
81+
82+
```python
83+
px.scatter_matrix(iris, dimensions=["sepal_width", "sepal_length", "petal_width", "petal_length"], color="species")
84+
```
85+
86+
```python
87+
px.parallel_coordinates(iris, color="species_id", labels={"species_id": "Species",
88+
"sepal_width": "Sepal Width", "sepal_length": "Sepal Length",
89+
"petal_width": "Petal Width", "petal_length": "Petal Length", },
90+
color_continuous_scale=px.colors.diverging.Tealrose, color_continuous_midpoint=2)
91+
```
92+
93+
```python
94+
px.parallel_categories(tips, color="size", color_continuous_scale=px.colors.sequential.Inferno)
95+
```
96+
97+
```python
98+
px.scatter(tips, x="total_bill", y="tip", color="size", facet_col="sex",
99+
color_continuous_scale=px.colors.sequential.Viridis, render_mode="webgl")
100+
```
101+
102+
```python
103+
px.scatter(gapminder.query("year==2007"), x="gdpPercap", y="lifeExp", size="pop", color="continent",
104+
hover_name="country", log_x=True, size_max=60)
105+
```
106+
107+
```python
108+
px.scatter(gapminder, x="gdpPercap", y="lifeExp", animation_frame="year", animation_group="country",
109+
size="pop", color="continent", hover_name="country", facet_col="continent",
110+
log_x=True, size_max=45, range_x=[100,100000], range_y=[25,90])
111+
```
112+
113+
```python
114+
px.line(gapminder, x="year", y="lifeExp", color="continent", line_group="country", hover_name="country",
115+
line_shape="spline")
116+
```
117+
118+
## Visualize Distributions
119+
120+
```python
121+
px.density_contour(iris, x="sepal_width", y="sepal_length")
122+
```
123+
124+
```python
125+
px.density_contour(iris, x="sepal_width", y="sepal_length", color="species", marginal_x="rug", marginal_y="histogram")
126+
```
127+
128+
```python
129+
px.bar(tips, x="sex", y="total_bill", color="smoker", barmode="group")
130+
```
131+
132+
```python
133+
px.bar(tips, x="sex", y="total_bill", color="smoker", barmode="group", facet_row="time", facet_col="day",
134+
category_orders={"day": ["Thur", "Fri", "Sat", "Sun"], "time": ["Lunch", "Dinner"]})
135+
```
136+
137+
```python
138+
px.histogram(tips, x="total_bill", y="tip", color="sex", marginal="rug", hover_data=tips.columns)
139+
```
140+
141+
```python
142+
px.histogram(tips, x="sex", y="tip", histfunc="avg", color="smoker", barmode="group",
143+
facet_row="time", facet_col="day", category_orders={"day": ["Thur", "Fri", "Sat", "Sun"],
144+
"time": ["Lunch", "Dinner"]})
145+
```
146+
147+
```python
148+
px.box(tips, x="day", y="total_bill", color="smoker", notched=True)
149+
```
150+
151+
```python
152+
px.violin(tips, y="tip", x="smoker", color="sex", box=True, points="all", hover_data=tips.columns)
153+
```
154+
155+
## Ternary Coordinates
156+
157+
```python
158+
px.scatter_ternary(election, a="Joly", b="Coderre", c="Bergeron", color="winner", size="total", hover_name="district",
159+
size_max=15, color_discrete_map = {"Joly": "blue", "Bergeron": "green", "Coderre":"red"} )
160+
```
161+
162+
```python
163+
px.line_ternary(election, a="Joly", b="Coderre", c="Bergeron", color="winner", line_dash="winner")
164+
```
165+
166+
## 3D Coordinates
167+
168+
```python
169+
px.scatter_3d(election, x="Joly", y="Coderre", z="Bergeron", color="winner", size="total", hover_name="district",
170+
symbol="result", color_discrete_map = {"Joly": "blue", "Bergeron": "green", "Coderre":"red"})
171+
```
172+
173+
```python
174+
px.line_3d(election, x="Joly", y="Coderre", z="Bergeron", color="winner", line_dash="winner")
175+
```
176+
177+
## Polar Coordinates
178+
179+
```python
180+
px.scatter_polar(wind, r="value", theta="direction", color="strength", symbol="strength",
181+
color_discrete_sequence=px.colors.sequential.Plotly[-2::-1])
182+
```
183+
184+
```python
185+
px.line_polar(wind, r="value", theta="direction", color="strength", line_close=True,
186+
color_discrete_sequence=px.colors.sequential.Plotly[-2::-1])
187+
```
188+
189+
```python
190+
px.bar_polar(wind, r="value", theta="direction", color="strength", template="plotly_dark",
191+
color_discrete_sequence= px.colors.sequential.Plotly[-2::-1])
192+
```
193+
194+
## Maps
195+
196+
```python
197+
px.set_mapbox_access_token(open(".mapbox_token").read())
198+
px.scatter_mapbox(carshare, lat="centroid_lat", lon="centroid_lon", color="peak_hour", size="car_hours",
199+
color_continuous_scale=px.colors.cyclical.IceFire, size_max=15, zoom=10)
200+
```
201+
202+
```python
203+
px.set_mapbox_access_token(open(".mapbox_token").read())
204+
px.line_mapbox(carshare, lat="centroid_lat", lon="centroid_lon", color="peak_hour")
205+
```
206+
207+
```python
208+
px.scatter_geo(gapminder, locations="iso_alpha", color="continent", hover_name="country", size="pop",
209+
animation_frame="year", projection="natural earth")
210+
```
211+
212+
```python
213+
px.line_geo(gapminder.query("year==2007"), locations="iso_alpha", color="continent", projection="orthographic")
214+
```
215+
216+
```python
217+
px.choropleth(gapminder, locations="iso_alpha", color="lifeExp", hover_name="country", animation_frame="year",
218+
color_continuous_scale=px.colors.sequential.Plasma)
219+
```
220+
221+
## Built-in Color Scales and Sequences (and a way to see them!)
222+
223+
```python
224+
px.colors.qualitative.swatches()
225+
```
226+
227+
```python
228+
px.colors.sequential.swatches()
229+
```
230+
231+
```python
232+
px.colors.diverging.swatches()
233+
```
234+
235+
```python
236+
px.colors.cyclical.swatches()
237+
```
238+
239+
```python
240+
px.colors.colorbrewer.swatches()
241+
```
242+
243+
```python
244+
px.colors.cmocean.swatches()
245+
```
246+
247+
```python
248+
px.colors.carto.swatches()
249+
```
250+
251+
# Next steps
252+
253+
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](https://plotly.github.io/plotly_express/plotly_express/) or just copy-paste from the examples above!

make_docs.sh

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,43 @@
11
#!/bin/bash
22

3+
# stop on errors
34
set -e
5+
6+
# install everything including local version
47
pip install -r requirements.txt
5-
jupyter nbconvert gallery.ipynb --execute --output-dir=docs --output=index --template=docs/nb.tpl
6-
jupyter nbconvert walkthrough.ipynb --execute --output-dir=docs --template=docs/nb.tpl
7-
pdoc plotly_express --html --html-dir=docs --overwrite --template-dir=docs/templates
8+
9+
# reset doc build dir
10+
rm -rf doc_build
11+
mkdir doc_build
12+
13+
# generate HTML reference docs
14+
pdoc plotly_express --html --html-dir=doc_build --overwrite --template-dir=docs/templates
15+
16+
for NB in walkthrough gallery
17+
do
18+
# make unexecuted IPYNB files from MD files (overwrites)
19+
jupytext --to notebook $NB.md
20+
21+
# create executed IPYNB files in the build dir
22+
jupyter nbconvert --execute --to notebook $NB.ipynb --output doc_build/$NB.ipynb
23+
24+
# convert executed doc_build/IPYNB files to doc_build/HTML using template
25+
jupyter nbconvert doc_build/$NB.ipynb --template=docs/nb.tpl
26+
done
27+
28+
29+
cd doc_build
30+
echo www.plotly.express >> CNAME
31+
echo plotly_express >> requirements.txt
32+
mv gallery.html index.html
33+
34+
# push to gh-pages
35+
git init
36+
git add .
37+
git commit -m doc_build
38+
git push --force git@github.com:plotly/plotly_express.git master:gh-pages
39+
40+
# clean up
41+
cd ..
42+
rm -rf doc_build
43+

walkthrough.ipynb

Lines changed: 0 additions & 31119 deletions
This file was deleted.

0 commit comments

Comments
 (0)