Skip to content

Commit 8e97700

Browse files
committed
percy tests
1 parent 87c3bc1 commit 8e97700

File tree

2 files changed

+256
-0
lines changed

2 files changed

+256
-0
lines changed

.circleci/config.yml

+31
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,37 @@ jobs:
160160
command: 'cd packages/python/plotly; tox -e py37-optional'
161161
no_output_timeout: 20m
162162

163+
python-3.7-percy:
164+
docker:
165+
- image: circleci/python:3.7-stretch-node-browsers
166+
167+
environment:
168+
PERCY_ENABLED: True
169+
PERCY_PROJECT: plotly/plotly.py
170+
171+
steps:
172+
- checkout
173+
- run:
174+
name: Inject Percy Environment variables
175+
command: |
176+
echo 'export PERCY_TOKEN="$PERCY_PYTHON_TOKEN_V0"' >> $BASH_ENV
177+
178+
- run:
179+
name: Install requirements
180+
command: |
181+
pip install -e ./packages/python/plotly
182+
183+
- run:
184+
name: Build html figures
185+
command: |
186+
python tests/percy/plotly.express.py
187+
188+
- run:
189+
name: Run percy snapshots
190+
command: |
191+
npx percy snapshot tests/percy/
192+
rm tests/percy/*.html
193+
163194
# Plot.ly
164195
python-2.7-plot_ly:
165196
docker:

test/percy/plotly-express.py

+225
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
## This script uses px functions to generate html figures, which will be
2+
## tested with percy.
3+
4+
import plotly.express as px
5+
print(px.data.iris.__doc__)
6+
px.data.iris().head()
7+
8+
# #### Scatter and Line plots
9+
10+
import plotly.express as px
11+
iris = px.data.iris()
12+
fig = px.scatter(iris, x="sepal_width", y="sepal_length")
13+
fig.write_html('scatter.html')
14+
15+
import plotly.express as px
16+
iris = px.data.iris()
17+
fig = px.scatter(iris, x="sepal_width", y="sepal_length", color="species")
18+
fig.write_html('scatter_color.html')
19+
20+
import plotly.express as px
21+
iris = px.data.iris()
22+
fig = px.scatter(iris, x="sepal_width", y="sepal_length", color="species", marginal_y="rug", marginal_x="histogram")
23+
fig.write_html('scatter_marginal.html')
24+
25+
import plotly.express as px
26+
iris = px.data.iris()
27+
fig = px.scatter(iris, x="sepal_width", y="sepal_length", color="species", marginal_y="violin",
28+
marginal_x="box", trendline="ols")
29+
fig.write_html('scatter_trendline.html')
30+
31+
import plotly.express as px
32+
iris = px.data.iris()
33+
iris["e"] = iris["sepal_width"]/100
34+
fig = px.scatter(iris, x="sepal_width", y="sepal_length", color="species", error_x="e", error_y="e")
35+
fig.write_html('scatter_errorbar.html')
36+
37+
import plotly.express as px
38+
tips = px.data.tips()
39+
fig = px.scatter(tips, x="total_bill", y="tip", facet_row="time", facet_col="day", color="smoker", trendline="ols",
40+
category_orders={"day": ["Thur", "Fri", "Sat", "Sun"], "time": ["Lunch", "Dinner"]})
41+
fig.write_html('scatter_categories.html')
42+
43+
import plotly.express as px
44+
iris = px.data.iris()
45+
fig = px.scatter_matrix(iris)
46+
fig.write_html('scatter_matrix.html')
47+
48+
import plotly.express as px
49+
iris = px.data.iris()
50+
fig = px.scatter_matrix(iris, dimensions=["sepal_width", "sepal_length", "petal_width", "petal_length"], color="species")
51+
fig.write_html('scatter_matrix_dimensions.html')
52+
53+
import plotly.express as px
54+
iris = px.data.iris()
55+
fig = px.parallel_coordinates(iris, color="species_id", labels={"species_id": "Species",
56+
"sepal_width": "Sepal Width", "sepal_length": "Sepal Length",
57+
"petal_width": "Petal Width", "petal_length": "Petal Length", },
58+
color_continuous_scale=px.colors.diverging.Tealrose, color_continuous_midpoint=2)
59+
fig.write_html('parallel_coordinates.html')
60+
61+
import plotly.express as px
62+
tips = px.data.tips()
63+
fig = px.parallel_categories(tips, color="size", color_continuous_scale=px.colors.sequential.Inferno)
64+
fig.write_html('parallel_categories.html')
65+
66+
import plotly.express as px
67+
tips = px.data.tips()
68+
fig = px.scatter(tips, x="total_bill", y="tip", color="size", facet_col="sex",
69+
color_continuous_scale=px.colors.sequential.Viridis, render_mode="webgl")
70+
fig.write_html('scatter_webgl.html')
71+
72+
import plotly.express as px
73+
gapminder = px.data.gapminder()
74+
fig = px.scatter(gapminder.query("year==2007"), x="gdpPercap", y="lifeExp", size="pop", color="continent",
75+
hover_name="country", log_x=True, size_max=60)
76+
fig.write_html('scatter_hover.html')
77+
78+
import plotly.express as px
79+
gapminder = px.data.gapminder()
80+
fig = px.scatter(gapminder, x="gdpPercap", y="lifeExp", animation_frame="year", animation_group="country",
81+
size="pop", color="continent", hover_name="country", facet_col="continent",
82+
log_x=True, size_max=45, range_x=[100,100000], range_y=[25,90])
83+
fig.write_html('scatter_log.html')
84+
85+
import plotly.express as px
86+
gapminder = px.data.gapminder()
87+
fig = px.line(gapminder, x="year", y="lifeExp", color="continent", line_group="country", hover_name="country",
88+
line_shape="spline", render_mode="svg")
89+
fig.write_html('line.html')
90+
91+
import plotly.express as px
92+
gapminder = px.data.gapminder()
93+
fig = px.area(gapminder, x="year", y="pop", color="continent", line_group="country")
94+
fig.write_html('area.html')
95+
96+
# #### Visualize Distributions
97+
98+
import plotly.express as px
99+
iris = px.data.iris()
100+
fig = px.density_contour(iris, x="sepal_width", y="sepal_length")
101+
fig.write_html('density_contour.html')
102+
103+
import plotly.express as px
104+
iris = px.data.iris()
105+
fig = px.density_contour(iris, x="sepal_width", y="sepal_length", color="species", marginal_x="rug", marginal_y="histogram")
106+
fig.write_html('density_contour_marginal.html')
107+
108+
import plotly.express as px
109+
iris = px.data.iris()
110+
fig = px.density_heatmap(iris, x="sepal_width", y="sepal_length", marginal_x="rug", marginal_y="histogram")
111+
fig.write_html('density_heatmap.html')
112+
113+
import plotly.express as px
114+
tips = px.data.tips()
115+
fig = px.bar(tips, x="sex", y="total_bill", color="smoker", barmode="group")
116+
fig.write_html('bar.html')
117+
118+
import plotly.express as px
119+
tips = px.data.tips()
120+
fig = px.bar(tips, x="sex", y="total_bill", color="smoker", barmode="group", facet_row="time", facet_col="day",
121+
category_orders={"day": ["Thur", "Fri", "Sat", "Sun"], "time": ["Lunch", "Dinner"]})
122+
fig.write_html('bar_facet.html')
123+
124+
import plotly.express as px
125+
tips = px.data.tips()
126+
fig = px.histogram(tips, x="total_bill", y="tip", color="sex", marginal="rug", hover_data=tips.columns)
127+
fig.write_html('histogram.html')
128+
129+
import plotly.express as px
130+
tips = px.data.tips()
131+
fig = px.histogram(tips, x="sex", y="tip", histfunc="avg", color="smoker", barmode="group",
132+
facet_row="time", facet_col="day", category_orders={"day": ["Thur", "Fri", "Sat", "Sun"],
133+
"time": ["Lunch", "Dinner"]})
134+
fig.write_html('histogram_histfunc.html')
135+
136+
import plotly.express as px
137+
tips = px.data.tips()
138+
fig = px.strip(tips, x="total_bill", y="time", orientation="h", color="smoker")
139+
fig.write_html('strip.html')
140+
141+
import plotly.express as px
142+
tips = px.data.tips()
143+
fig = px.box(tips, x="day", y="total_bill", color="smoker", notched=True)
144+
fig.write_html('box.html')
145+
146+
import plotly.express as px
147+
tips = px.data.tips()
148+
fig = px.violin(tips, y="tip", x="smoker", color="sex", box=True, points="all", hover_data=tips.columns)
149+
fig.write_html('violin.html')
150+
151+
# #### Ternary Coordinates
152+
153+
import plotly.express as px
154+
election = px.data.election()
155+
fig = px.scatter_ternary(election, a="Joly", b="Coderre", c="Bergeron", color="winner", size="total", hover_name="district",
156+
size_max=15, color_discrete_map = {"Joly": "blue", "Bergeron": "green", "Coderre":"red"} )
157+
fig.write_html('scatter_ternary.html')
158+
159+
import plotly.express as px
160+
election = px.data.election()
161+
fig = px.line_ternary(election, a="Joly", b="Coderre", c="Bergeron", color="winner", line_dash="winner")
162+
fig.write_html('line_ternary.html')
163+
164+
# #### 3D Coordinates
165+
166+
import plotly.express as px
167+
election = px.data.election()
168+
fig = px.scatter_3d(election, x="Joly", y="Coderre", z="Bergeron", color="winner", size="total", hover_name="district",
169+
symbol="result", color_discrete_map = {"Joly": "blue", "Bergeron": "green", "Coderre":"red"})
170+
fig.write_html('scatter_3d.html')
171+
172+
import plotly.express as px
173+
election = px.data.election()
174+
fig = px.line_3d(election, x="Joly", y="Coderre", z="Bergeron", color="winner", line_dash="winner")
175+
fig.write_html('line_3d.html')
176+
177+
# #### Polar Coordinates
178+
179+
import plotly.express as px
180+
wind = px.data.wind()
181+
fig = px.scatter_polar(wind, r="frequency", theta="direction", color="strength", symbol="strength",
182+
color_discrete_sequence=px.colors.sequential.Plasma[-2::-1])
183+
fig.write_html('scatter_polar.html')
184+
185+
import plotly.express as px
186+
wind = px.data.wind()
187+
fig = px.line_polar(wind, r="frequency", theta="direction", color="strength", line_close=True,
188+
color_discrete_sequence=px.colors.sequential.Plasma[-2::-1])
189+
fig.write_html('line_polar.html')
190+
191+
import plotly.express as px
192+
wind = px.data.wind()
193+
fig = px.bar_polar(wind, r="frequency", theta="direction", color="strength", template="plotly_dark",
194+
color_discrete_sequence= px.colors.sequential.Plasma[-2::-1])
195+
fig.write_html('bar_polar.html')
196+
197+
# #### Maps
198+
199+
import plotly.express as px
200+
carshare = px.data.carshare()
201+
fig = px.scatter_mapbox(carshare, lat="centroid_lat", lon="centroid_lon", color="peak_hour", size="car_hours",
202+
color_continuous_scale=px.colors.cyclical.IceFire, size_max=15, zoom=10)
203+
fig.write_html('scatter_mapbox.html')
204+
205+
import plotly.express as px
206+
carshare = px.data.carshare()
207+
fig = px.line_mapbox(carshare, lat="centroid_lat", lon="centroid_lon", color="peak_hour")
208+
fig.write_html('line_mapbox.html')
209+
210+
import plotly.express as px
211+
gapminder = px.data.gapminder()
212+
fig = px.scatter_geo(gapminder, locations="iso_alpha", color="continent", hover_name="country", size="pop",
213+
animation_frame="year", projection="natural earth")
214+
fig.write_html('scatter_geo.html')
215+
216+
import plotly.express as px
217+
gapminder = px.data.gapminder()
218+
fig = px.line_geo(gapminder.query("year==2007"), locations="iso_alpha", color="continent", projection="orthographic")
219+
fig.write_html('line_geo.html')
220+
221+
import plotly.express as px
222+
gapminder = px.data.gapminder()
223+
fig = px.choropleth(gapminder, locations="iso_alpha", color="lifeExp", hover_name="country", animation_frame="year", range_color=[20,80])
224+
fig.write_html('choropleth.html')
225+

0 commit comments

Comments
 (0)