Skip to content

Commit 81ff26a

Browse files
committed
improvement
1 parent 15bebab commit 81ff26a

File tree

2 files changed

+41
-38
lines changed

2 files changed

+41
-38
lines changed

.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ jobs:
103103
name: Build html figures
104104
command: |
105105
. venv/bin/activate
106-
pip install pandas statsmodels
106+
pip install pandas statsmodels --quiet
107107
python test/percy/plotly-express.py
108108
- run:
109109
name: Run percy snapshots

test/percy/plotly-express.py

+40-37
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
## This script uses px functions to generate html figures, which will be
22
## tested with percy.
33

4+
import os
5+
dir_name = os.path.join("test", "percy")
6+
47
import plotly.express as px
58
print(px.data.iris.__doc__)
69
px.data.iris().head()
@@ -10,216 +13,216 @@
1013
import plotly.express as px
1114
iris = px.data.iris()
1215
fig = px.scatter(iris, x="sepal_width", y="sepal_length")
13-
fig.write_html('scatter.html')
16+
fig.write_html(os.path.join(dir_name, 'scatter.html'))
1417

1518
import plotly.express as px
1619
iris = px.data.iris()
1720
fig = px.scatter(iris, x="sepal_width", y="sepal_length", color="species")
18-
fig.write_html('scatter_color.html')
21+
fig.write_html(os.path.join(dir_name, 'scatter_color.html'))
1922

2023
import plotly.express as px
2124
iris = px.data.iris()
2225
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')
26+
fig.write_html(os.path.join(dir_name, 'scatter_marginal.html'))
2427

2528
import plotly.express as px
2629
iris = px.data.iris()
2730
fig = px.scatter(iris, x="sepal_width", y="sepal_length", color="species", marginal_y="violin",
2831
marginal_x="box", trendline="ols")
29-
fig.write_html('scatter_trendline.html')
32+
fig.write_html(os.path.join(dir_name, 'scatter_trendline.html'))
3033

3134
import plotly.express as px
3235
iris = px.data.iris()
3336
iris["e"] = iris["sepal_width"]/100
3437
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')
38+
fig.write_html(os.path.join(dir_name, 'scatter_errorbar.html'))
3639

3740
import plotly.express as px
3841
tips = px.data.tips()
3942
fig = px.scatter(tips, x="total_bill", y="tip", facet_row="time", facet_col="day", color="smoker", trendline="ols",
4043
category_orders={"day": ["Thur", "Fri", "Sat", "Sun"], "time": ["Lunch", "Dinner"]})
41-
fig.write_html('scatter_categories.html')
44+
fig.write_html(os.path.join(dir_name, 'scatter_categories.html'))
4245

4346
import plotly.express as px
4447
iris = px.data.iris()
4548
fig = px.scatter_matrix(iris)
46-
fig.write_html('scatter_matrix.html')
49+
fig.write_html(os.path.join(dir_name, 'scatter_matrix.html'))
4750

4851
import plotly.express as px
4952
iris = px.data.iris()
5053
fig = px.scatter_matrix(iris, dimensions=["sepal_width", "sepal_length", "petal_width", "petal_length"], color="species")
51-
fig.write_html('scatter_matrix_dimensions.html')
54+
fig.write_html(os.path.join(dir_name, 'scatter_matrix_dimensions.html'))
5255

5356
import plotly.express as px
5457
iris = px.data.iris()
5558
fig = px.parallel_coordinates(iris, color="species_id", labels={"species_id": "Species",
5659
"sepal_width": "Sepal Width", "sepal_length": "Sepal Length",
5760
"petal_width": "Petal Width", "petal_length": "Petal Length", },
5861
color_continuous_scale=px.colors.diverging.Tealrose, color_continuous_midpoint=2)
59-
fig.write_html('parallel_coordinates.html')
62+
fig.write_html(os.path.join(dir_name, 'parallel_coordinates.html'))
6063

6164
import plotly.express as px
6265
tips = px.data.tips()
6366
fig = px.parallel_categories(tips, color="size", color_continuous_scale=px.colors.sequential.Inferno)
64-
fig.write_html('parallel_categories.html')
67+
fig.write_html(os.path.join(dir_name, 'parallel_categories.html'))
6568

6669
import plotly.express as px
6770
tips = px.data.tips()
6871
fig = px.scatter(tips, x="total_bill", y="tip", color="size", facet_col="sex",
6972
color_continuous_scale=px.colors.sequential.Viridis, render_mode="webgl")
70-
fig.write_html('scatter_webgl.html')
73+
fig.write_html(os.path.join(dir_name, 'scatter_webgl.html'))
7174

7275
import plotly.express as px
7376
gapminder = px.data.gapminder()
7477
fig = px.scatter(gapminder.query("year==2007"), x="gdpPercap", y="lifeExp", size="pop", color="continent",
7578
hover_name="country", log_x=True, size_max=60)
76-
fig.write_html('scatter_hover.html')
79+
fig.write_html(os.path.join(dir_name, 'scatter_hover.html'))
7780

7881
import plotly.express as px
7982
gapminder = px.data.gapminder()
8083
fig = px.scatter(gapminder, x="gdpPercap", y="lifeExp", animation_frame="year", animation_group="country",
8184
size="pop", color="continent", hover_name="country", facet_col="continent",
8285
log_x=True, size_max=45, range_x=[100,100000], range_y=[25,90])
83-
fig.write_html('scatter_log.html')
86+
fig.write_html(os.path.join(dir_name, 'scatter_log.html'))
8487

8588
import plotly.express as px
8689
gapminder = px.data.gapminder()
8790
fig = px.line(gapminder, x="year", y="lifeExp", color="continent", line_group="country", hover_name="country",
8891
line_shape="spline", render_mode="svg")
89-
fig.write_html('line.html')
92+
fig.write_html(os.path.join(dir_name, 'line.html'))
9093

9194
import plotly.express as px
9295
gapminder = px.data.gapminder()
9396
fig = px.area(gapminder, x="year", y="pop", color="continent", line_group="country")
94-
fig.write_html('area.html')
97+
fig.write_html(os.path.join(dir_name, 'area.html'))
9598

9699
# #### Visualize Distributions
97100

98101
import plotly.express as px
99102
iris = px.data.iris()
100103
fig = px.density_contour(iris, x="sepal_width", y="sepal_length")
101-
fig.write_html('density_contour.html')
104+
fig.write_html(os.path.join(dir_name, 'density_contour.html'))
102105

103106
import plotly.express as px
104107
iris = px.data.iris()
105108
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')
109+
fig.write_html(os.path.join(dir_name, 'density_contour_marginal.html'))
107110

108111
import plotly.express as px
109112
iris = px.data.iris()
110113
fig = px.density_heatmap(iris, x="sepal_width", y="sepal_length", marginal_x="rug", marginal_y="histogram")
111-
fig.write_html('density_heatmap.html')
114+
fig.write_html(os.path.join(dir_name, 'density_heatmap.html'))
112115

113116
import plotly.express as px
114117
tips = px.data.tips()
115118
fig = px.bar(tips, x="sex", y="total_bill", color="smoker", barmode="group")
116-
fig.write_html('bar.html')
119+
fig.write_html(os.path.join(dir_name, 'bar.html'))
117120

118121
import plotly.express as px
119122
tips = px.data.tips()
120123
fig = px.bar(tips, x="sex", y="total_bill", color="smoker", barmode="group", facet_row="time", facet_col="day",
121124
category_orders={"day": ["Thur", "Fri", "Sat", "Sun"], "time": ["Lunch", "Dinner"]})
122-
fig.write_html('bar_facet.html')
125+
fig.write_html(os.path.join(dir_name, 'bar_facet.html'))
123126

124127
import plotly.express as px
125128
tips = px.data.tips()
126129
fig = px.histogram(tips, x="total_bill", y="tip", color="sex", marginal="rug", hover_data=tips.columns)
127-
fig.write_html('histogram.html')
130+
fig.write_html(os.path.join(dir_name, 'histogram.html'))
128131

129132
import plotly.express as px
130133
tips = px.data.tips()
131134
fig = px.histogram(tips, x="sex", y="tip", histfunc="avg", color="smoker", barmode="group",
132135
facet_row="time", facet_col="day", category_orders={"day": ["Thur", "Fri", "Sat", "Sun"],
133136
"time": ["Lunch", "Dinner"]})
134-
fig.write_html('histogram_histfunc.html')
137+
fig.write_html(os.path.join(dir_name, 'histogram_histfunc.html'))
135138

136139
import plotly.express as px
137140
tips = px.data.tips()
138141
fig = px.strip(tips, x="total_bill", y="time", orientation="h", color="smoker")
139-
fig.write_html('strip.html')
142+
fig.write_html(os.path.join(dir_name, 'strip.html'))
140143

141144
import plotly.express as px
142145
tips = px.data.tips()
143146
fig = px.box(tips, x="day", y="total_bill", color="smoker", notched=True)
144-
fig.write_html('box.html')
147+
fig.write_html(os.path.join(dir_name, 'box.html'))
145148

146149
import plotly.express as px
147150
tips = px.data.tips()
148151
fig = px.violin(tips, y="tip", x="smoker", color="sex", box=True, points="all", hover_data=tips.columns)
149-
fig.write_html('violin.html')
152+
fig.write_html(os.path.join(dir_name, 'violin.html'))
150153

151154
# #### Ternary Coordinates
152155

153156
import plotly.express as px
154157
election = px.data.election()
155158
fig = px.scatter_ternary(election, a="Joly", b="Coderre", c="Bergeron", color="winner", size="total", hover_name="district",
156159
size_max=15, color_discrete_map = {"Joly": "blue", "Bergeron": "green", "Coderre":"red"} )
157-
fig.write_html('scatter_ternary.html')
160+
fig.write_html(os.path.join(dir_name, 'scatter_ternary.html'))
158161

159162
import plotly.express as px
160163
election = px.data.election()
161164
fig = px.line_ternary(election, a="Joly", b="Coderre", c="Bergeron", color="winner", line_dash="winner")
162-
fig.write_html('line_ternary.html')
165+
fig.write_html(os.path.join(dir_name, 'line_ternary.html'))
163166

164167
# #### 3D Coordinates
165168

166169
import plotly.express as px
167170
election = px.data.election()
168171
fig = px.scatter_3d(election, x="Joly", y="Coderre", z="Bergeron", color="winner", size="total", hover_name="district",
169172
symbol="result", color_discrete_map = {"Joly": "blue", "Bergeron": "green", "Coderre":"red"})
170-
fig.write_html('scatter_3d.html')
173+
fig.write_html(os.path.join(dir_name, 'scatter_3d.html'))
171174

172175
import plotly.express as px
173176
election = px.data.election()
174177
fig = px.line_3d(election, x="Joly", y="Coderre", z="Bergeron", color="winner", line_dash="winner")
175-
fig.write_html('line_3d.html')
178+
fig.write_html(os.path.join(dir_name, 'line_3d.html'))
176179

177180
# #### Polar Coordinates
178181

179182
import plotly.express as px
180183
wind = px.data.wind()
181184
fig = px.scatter_polar(wind, r="frequency", theta="direction", color="strength", symbol="strength",
182185
color_discrete_sequence=px.colors.sequential.Plasma[-2::-1])
183-
fig.write_html('scatter_polar.html')
186+
fig.write_html(os.path.join(dir_name, 'scatter_polar.html'))
184187

185188
import plotly.express as px
186189
wind = px.data.wind()
187190
fig = px.line_polar(wind, r="frequency", theta="direction", color="strength", line_close=True,
188191
color_discrete_sequence=px.colors.sequential.Plasma[-2::-1])
189-
fig.write_html('line_polar.html')
192+
fig.write_html(os.path.join(dir_name, 'line_polar.html'))
190193

191194
import plotly.express as px
192195
wind = px.data.wind()
193196
fig = px.bar_polar(wind, r="frequency", theta="direction", color="strength", template="plotly_dark",
194197
color_discrete_sequence= px.colors.sequential.Plasma[-2::-1])
195-
fig.write_html('bar_polar.html')
198+
fig.write_html(os.path.join(dir_name, 'bar_polar.html'))
196199

197200
# #### Maps
198201

199202
import plotly.express as px
200203
carshare = px.data.carshare()
201204
fig = px.scatter_mapbox(carshare, lat="centroid_lat", lon="centroid_lon", color="peak_hour", size="car_hours",
202205
color_continuous_scale=px.colors.cyclical.IceFire, size_max=15, zoom=10)
203-
fig.write_html('scatter_mapbox.html')
206+
fig.write_html(os.path.join(dir_name, 'scatter_mapbox.html'))
204207

205208
import plotly.express as px
206209
carshare = px.data.carshare()
207210
fig = px.line_mapbox(carshare, lat="centroid_lat", lon="centroid_lon", color="peak_hour")
208-
fig.write_html('line_mapbox.html')
211+
fig.write_html(os.path.join(dir_name, 'line_mapbox.html'))
209212

210213
import plotly.express as px
211214
gapminder = px.data.gapminder()
212215
fig = px.scatter_geo(gapminder, locations="iso_alpha", color="continent", hover_name="country", size="pop",
213216
animation_frame="year", projection="natural earth")
214-
fig.write_html('scatter_geo.html')
217+
fig.write_html(os.path.join(dir_name, 'scatter_geo.html'))
215218

216219
import plotly.express as px
217220
gapminder = px.data.gapminder()
218221
fig = px.line_geo(gapminder.query("year==2007"), locations="iso_alpha", color="continent", projection="orthographic")
219-
fig.write_html('line_geo.html')
222+
fig.write_html(os.path.join(dir_name, 'line_geo.html'))
220223

221224
import plotly.express as px
222225
gapminder = px.data.gapminder()
223226
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')
227+
fig.write_html(os.path.join(dir_name, 'choropleth.html'))
225228

0 commit comments

Comments
 (0)