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