|
19 | 19 | "import pandas as pd\n", |
20 | 20 | "import xarray as xr\n", |
21 | 21 | "\n", |
22 | | - "import xarray_plotly" |
| 22 | + "from xarray_plotly import xpx" |
23 | 23 | ] |
24 | 24 | }, |
25 | 25 | { |
|
57 | 57 | "da.coords[\"station\"].attrs = {\"long_name\": \"Measurement Station\"}\n", |
58 | 58 | "\n", |
59 | 59 | "# Labels are automatically extracted from attrs\n", |
60 | | - "fig = da.plotly.line(title=\"Temperature with Auto-Labels\")\n", |
| 60 | + "fig = xpx(da).line(title=\"Temperature with Auto-Labels\")\n", |
61 | 61 | "fig" |
62 | 62 | ] |
63 | 63 | }, |
|
76 | 76 | "metadata": {}, |
77 | 77 | "outputs": [], |
78 | 78 | "source": [ |
79 | | - "fig = da.plotly.line(\n", |
| 79 | + "fig = xpx(da).line(\n", |
80 | 80 | " labels={\n", |
81 | 81 | " \"temperature\": \"Temp (°C)\",\n", |
82 | 82 | " \"time\": \"Date\",\n", |
|
117 | 117 | ")\n", |
118 | 118 | "\n", |
119 | 119 | "# Use line_dash for one dimension, color for another\n", |
120 | | - "fig = da_complex.sel(city=\"NYC\").plotly.line(\n", |
| 120 | + "fig = xpx(da_complex.sel(city=\"NYC\")).line(\n", |
121 | 121 | " color=\"scenario\",\n", |
122 | 122 | " line_dash=\"model\",\n", |
123 | 123 | " title=\"Multiple Visual Encodings\",\n", |
|
141 | 141 | "outputs": [], |
142 | 142 | "source": [ |
143 | 143 | "# Average over model dimension\n", |
144 | | - "fig = da_complex.mean(\"model\").plotly.line(\n", |
| 144 | + "fig = xpx(da_complex.mean(\"model\")).line(\n", |
145 | 145 | " facet_col=\"city\",\n", |
146 | 146 | " title=\"Ensemble Mean by City\",\n", |
147 | 147 | ")\n", |
|
155 | 155 | "outputs": [], |
156 | 156 | "source": [ |
157 | 157 | "# Select a specific slice\n", |
158 | | - "fig = da_complex.sel(scenario=\"SSP5\", model=\"GCM-A\").plotly.line(\n", |
| 158 | + "fig = xpx(da_complex.sel(scenario=\"SSP5\", model=\"GCM-A\")).line(\n", |
159 | 159 | " facet_col=\"city\",\n", |
160 | 160 | " title=\"SSP5 / GCM-A Projections\",\n", |
161 | 161 | ")\n", |
|
184 | 184 | "source": [ |
185 | 185 | "da_simple = da.sel(station=\"Urban\")\n", |
186 | 186 | "\n", |
187 | | - "fig = da_simple.plotly.line(\n", |
| 187 | + "fig = xpx(da_simple).line(\n", |
188 | 188 | " template=\"plotly_dark\",\n", |
189 | 189 | " title=\"Dark Theme\",\n", |
190 | 190 | ")\n", |
|
206 | 206 | "source": [ |
207 | 207 | "import plotly.express as px\n", |
208 | 208 | "\n", |
209 | | - "fig = da.plotly.line(\n", |
| 209 | + "fig = xpx(da).line(\n", |
210 | 210 | " color_discrete_sequence=px.colors.qualitative.Set2,\n", |
211 | 211 | " title=\"Custom Color Palette\",\n", |
212 | 212 | ")\n", |
|
233 | 233 | ")\n", |
234 | 234 | "\n", |
235 | 235 | "# Diverging colorscale centered at zero\n", |
236 | | - "fig = da_2d.plotly.imshow(\n", |
| 236 | + "fig = xpx(da_2d).imshow(\n", |
237 | 237 | " color_continuous_scale=\"RdBu_r\",\n", |
238 | 238 | " color_continuous_midpoint=0,\n", |
239 | 239 | " title=\"Diverging Colorscale\",\n", |
|
256 | 256 | "metadata": {}, |
257 | 257 | "outputs": [], |
258 | 258 | "source": [ |
259 | | - "fig = da.plotly.line()\n", |
| 259 | + "fig = xpx(da).line()\n", |
260 | 260 | "\n", |
261 | 261 | "# Add horizontal reference line\n", |
262 | 262 | "fig.add_hline(y=15, line_dash=\"dash\", line_color=\"gray\", annotation_text=\"Reference\")\n", |
|
289 | 289 | "metadata": {}, |
290 | 290 | "outputs": [], |
291 | 291 | "source": [ |
292 | | - "fig = da.plotly.line()\n", |
| 292 | + "fig = xpx(da).line()\n", |
293 | 293 | "\n", |
294 | 294 | "# Make all lines thicker\n", |
295 | 295 | "fig.update_traces(line_width=3)\n", |
|
349 | 349 | "# Rolling mean\n", |
350 | 350 | "da_smooth = da.rolling(time=7, center=True).mean()\n", |
351 | 351 | "\n", |
352 | | - "fig = da_smooth.plotly.line(\n", |
| 352 | + "fig = xpx(da_smooth).line(\n", |
353 | 353 | " title=\"7-Day Rolling Mean\",\n", |
354 | 354 | ")\n", |
355 | 355 | "fig" |
|
374 | 374 | "\n", |
375 | 375 | "monthly_mean = da_monthly.groupby(\"time.month\").mean()\n", |
376 | 376 | "\n", |
377 | | - "fig = monthly_mean.plotly.line(\n", |
| 377 | + "fig = xpx(monthly_mean).line(\n", |
378 | 378 | " title=\"Monthly Climatology\",\n", |
379 | 379 | ")\n", |
380 | 380 | "fig.update_xaxes(tickmode=\"array\", tickvals=list(range(1, 13)), \n", |
|
0 commit comments