|
1 | | -""" |
2 | | -xarray_plotly: Interactive Plotly Express plotting for xarray. |
| 1 | +"""Interactive Plotly Express plotting for xarray. |
3 | 2 |
|
4 | 3 | This package provides a `plotly` accessor for xarray DataArray objects, |
5 | 4 | enabling interactive visualization with Plotly Express. |
6 | 5 |
|
7 | | -Features |
8 | | --------- |
9 | | -- **Interactive plots**: Zoom, pan, hover, toggle traces |
10 | | -- **Automatic dimension assignment**: Dimensions fill slots (x, color, facet) by position |
11 | | -- **Multiple plot types**: line, bar, area, scatter, box, imshow |
12 | | -- **Faceting and animation**: Built-in subplot grids and animated plots |
13 | | -- **Customizable**: Returns Plotly Figure objects for further modification |
14 | | -
|
15 | | -Usage |
16 | | ------ |
17 | | -Accessor style:: |
| 6 | +Features: |
| 7 | + - **Interactive plots**: Zoom, pan, hover, toggle traces |
| 8 | + - **Automatic dimension assignment**: Dimensions fill slots (x, color, facet) by position |
| 9 | + - **Multiple plot types**: line, bar, area, scatter, box, imshow |
| 10 | + - **Faceting and animation**: Built-in subplot grids and animated plots |
| 11 | + - **Customizable**: Returns Plotly Figure objects for further modification |
18 | 12 |
|
19 | | - import xarray_plotly |
20 | | - fig = da.plotly.line() |
| 13 | +Usage: |
| 14 | + Accessor style:: |
21 | 15 |
|
22 | | -Function style (recommended for IDE completion):: |
23 | | -
|
24 | | - from xarray_plotly import xpx |
25 | | - fig = xpx(da).line() |
| 16 | + import xarray_plotly |
| 17 | + fig = da.plotly.line() |
26 | 18 |
|
27 | | -Examples |
28 | | --------- |
29 | | ->>> import xarray as xr |
30 | | ->>> import numpy as np |
31 | | ->>> from xarray_plotly import xpx |
| 19 | + Function style (recommended for IDE completion):: |
32 | 20 |
|
33 | | ->>> da = xr.DataArray( |
34 | | -... np.random.rand(10, 3, 2), |
35 | | -... dims=["time", "city", "scenario"], |
36 | | -... ) |
| 21 | + from xarray_plotly import xpx |
| 22 | + fig = xpx(da).line() |
37 | 23 |
|
38 | | ->>> # Auto-assignment: time->x, city->color, scenario->facet_col |
39 | | ->>> fig = xpx(da).line() |
40 | | -
|
41 | | ->>> # Explicit assignment |
42 | | ->>> fig = xpx(da).line(x="time", color="scenario", facet_col="city") |
| 24 | +Example: |
| 25 | + ```python |
| 26 | + import xarray as xr |
| 27 | + import numpy as np |
| 28 | + from xarray_plotly import xpx |
43 | 29 |
|
44 | | ->>> # Skip a slot with None |
45 | | ->>> fig = xpx(da).line(color=None) |
| 30 | + da = xr.DataArray( |
| 31 | + np.random.rand(10, 3, 2), |
| 32 | + dims=["time", "city", "scenario"], |
| 33 | + ) |
| 34 | + fig = xpx(da).line() # Auto: time->x, city->color, scenario->facet_col |
| 35 | + fig = xpx(da).line(x="time", color="scenario") # Explicit |
| 36 | + fig = xpx(da).line(color=None) # Skip slot |
| 37 | + ``` |
46 | 38 | """ |
47 | 39 |
|
48 | 40 | from importlib.metadata import version |
|
63 | 55 |
|
64 | 56 |
|
65 | 57 | def xpx(da: DataArray) -> DataArrayPlotlyAccessor: |
66 | | - """ |
67 | | - Get the plotly accessor for a DataArray with full IDE code completion. |
| 58 | + """Get the plotly accessor for a DataArray with full IDE code completion. |
68 | 59 |
|
69 | 60 | This is an alternative to `da.plotly` that provides proper type hints |
70 | 61 | and code completion in IDEs. |
71 | 62 |
|
72 | | - Parameters |
73 | | - ---------- |
74 | | - da : DataArray |
75 | | - The DataArray to plot. |
| 63 | + Args: |
| 64 | + da: The DataArray to plot. |
76 | 65 |
|
77 | | - Returns |
78 | | - ------- |
79 | | - DataArrayPlotlyAccessor |
80 | | - The accessor with plotting methods. |
| 66 | + Returns: |
| 67 | + The accessor with plotting methods (line, bar, area, scatter, box, imshow). |
81 | 68 |
|
82 | | - Examples |
83 | | - -------- |
84 | | - >>> from xarray_plotly import xpx |
85 | | - >>> fig = xpx(da).line() # Full code completion works here |
| 69 | + Example: |
| 70 | + ```python |
| 71 | + from xarray_plotly import xpx |
| 72 | + fig = xpx(da).line() # Full code completion works here |
| 73 | + ``` |
86 | 74 | """ |
87 | 75 | return DataArrayPlotlyAccessor(da) |
88 | 76 |
|
|
0 commit comments