Skip to content

Commit 2f790a2

Browse files
committed
Revert
1 parent 9b428e1 commit 2f790a2

1 file changed

Lines changed: 45 additions & 65 deletions

File tree

xarray_plotly/__init__.py

Lines changed: 45 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -12,43 +12,41 @@
1212
- **Customizable**: Returns Plotly Figure objects for further modification
1313
1414
Usage:
15-
Mos Recommended::
16-
17-
import xarray_plotly as xpx
18-
19-
fig = xpx(da).line() # Create plots
20-
combined = xpx.overlay(fig1, fig2) # Use helper functions
21-
2215
Accessor style::
2316
2417
import xarray_plotly
2518
fig = da.plotly.line()
19+
fig = ds.plotly.line() # Dataset: all variables
20+
21+
Function style (recommended for IDE completion)::
22+
23+
from xarray_plotly import xpx
24+
fig = xpx(da).line()
25+
fig = xpx(ds).line() # Dataset: all variables
2626
2727
Example:
2828
```python
2929
import xarray as xr
3030
import numpy as np
31-
import xarray_plotly as xpx
31+
from xarray_plotly import xpx
3232
3333
da = xr.DataArray(
3434
np.random.rand(10, 3, 2),
3535
dims=["time", "city", "scenario"],
3636
)
3737
fig = xpx(da).line() # Auto: time->x, city->color, scenario->facet_col
38+
fig = xpx(da).line(x="time", color="scenario") # Explicit
39+
fig = xpx(da).line(color=None) # Skip slot
3840
39-
# Combine figures
40-
area = xpx(da).area()
41-
line = xpx(da).line()
42-
combined = xpx.overlay(area, line)
41+
# Dataset: plot all variables (accessor or xpx)
42+
ds = xr.Dataset({"temp": da, "precip": da})
43+
fig = xpx(ds).line() # "variable" dimension for color
44+
fig = xpx(ds).line(facet_col="variable") # Facet by variable
4345
```
4446
"""
4547

46-
from __future__ import annotations
47-
48-
import sys
49-
import types
5048
from importlib.metadata import version
51-
from typing import TYPE_CHECKING, overload
49+
from typing import overload
5250

5351
from xarray import DataArray, Dataset, register_dataarray_accessor, register_dataset_accessor
5452

@@ -68,67 +66,49 @@
6866
"config",
6967
"overlay",
7068
"update_traces",
69+
"xpx",
7170
]
7271

73-
__version__ = version("xarray_plotly")
74-
75-
# Register the accessors
76-
register_dataarray_accessor("plotly")(DataArrayPlotlyAccessor)
77-
register_dataset_accessor("plotly")(DatasetPlotlyAccessor)
78-
79-
80-
class _CallableModule(types.ModuleType):
81-
"""A module that can be called as a function.
8272

83-
Enables the pattern::
84-
85-
import xarray_plotly as xpx
86-
fig = xpx(da).line() # Call module as function
87-
fig = xpx.overlay(a, b) # Access module attributes
88-
"""
73+
@overload
74+
def xpx(data: DataArray) -> DataArrayPlotlyAccessor: ...
8975

90-
@overload
91-
def __call__(self, data: DataArray) -> DataArrayPlotlyAccessor: ...
9276

93-
@overload
94-
def __call__(self, data: Dataset) -> DatasetPlotlyAccessor: ...
77+
@overload
78+
def xpx(data: Dataset) -> DatasetPlotlyAccessor: ...
9579

96-
def __call__(
97-
self, data: DataArray | Dataset
98-
) -> DataArrayPlotlyAccessor | DatasetPlotlyAccessor:
99-
"""Get the plotly accessor for a DataArray or Dataset.
10080

101-
Args:
102-
data: The DataArray or Dataset to plot.
81+
def xpx(data: DataArray | Dataset) -> DataArrayPlotlyAccessor | DatasetPlotlyAccessor:
82+
"""Get the plotly accessor for a DataArray or Dataset with full IDE code completion.
10383
104-
Returns:
105-
The accessor with plotting methods (line, bar, area, scatter, box, imshow, pie).
84+
This is an alternative to `da.plotly` / `ds.plotly` that provides proper type hints
85+
and code completion in IDEs.
10686
107-
Example:
108-
```python
109-
import xarray_plotly as xpx
87+
Args:
88+
data: The DataArray or Dataset to plot.
11089
111-
fig = xpx(da).line()
112-
fig = xpx(ds).line(var="temperature")
113-
```
114-
"""
115-
if isinstance(data, Dataset):
116-
return DatasetPlotlyAccessor(data)
117-
return DataArrayPlotlyAccessor(data)
90+
Returns:
91+
The accessor with plotting methods (line, bar, area, scatter, box, imshow).
11892
93+
Example:
94+
```python
95+
from xarray_plotly import xpx
11996
120-
# Make the module callable
121-
sys.modules[__name__].__class__ = _CallableModule
97+
# DataArray
98+
fig = xpx(da).line() # Full code completion works here
12299
123-
# For type checking, expose the call signature
124-
if TYPE_CHECKING:
100+
# Dataset
101+
fig = xpx(ds).line() # Plots all variables
102+
fig = xpx(ds).line(var="temperature") # Single variable
103+
```
104+
"""
105+
if isinstance(data, Dataset):
106+
return DatasetPlotlyAccessor(data)
107+
return DataArrayPlotlyAccessor(data)
125108

126-
@overload
127-
def __call__(data: DataArray) -> DataArrayPlotlyAccessor: ...
128109

129-
@overload
130-
def __call__(data: Dataset) -> DatasetPlotlyAccessor: ...
110+
__version__ = version("xarray_plotly")
131111

132-
def __call__(
133-
data: DataArray | Dataset,
134-
) -> DataArrayPlotlyAccessor | DatasetPlotlyAccessor: ...
112+
# Register the accessors
113+
register_dataarray_accessor("plotly")(DataArrayPlotlyAccessor)
114+
register_dataset_accessor("plotly")(DatasetPlotlyAccessor)

0 commit comments

Comments
 (0)