Skip to content

Commit 595eb43

Browse files
committed
Remove duplication from docs and docstrings
1 parent 213801d commit 595eb43

File tree

5 files changed

+84
-114
lines changed

5 files changed

+84
-114
lines changed

docs/api.md

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,12 @@
22

33
## xpx Function
44

5-
The recommended way to use xarray_plotly with full IDE code completion:
6-
7-
```python
8-
from xarray_plotly import xpx
9-
10-
fig = xpx(da).line()
11-
```
12-
135
::: xarray_plotly.xpx
146
options:
157
show_root_heading: true
168

179
## Accessor
1810

19-
The accessor style (`da.plotly.line()`) works but doesn't provide IDE code completion.
20-
2111
::: xarray_plotly.accessor.DataArrayPlotlyAccessor
2212
options:
2313
show_root_heading: true
@@ -44,31 +34,6 @@ The accessor style (`da.plotly.line()`) works but doesn't provide IDE code compl
4434

4535
## Configuration
4636

47-
Customize label extraction and slot assignment behavior:
48-
49-
```python
50-
from xarray_plotly import config, xpx
51-
52-
# View current options
53-
config.get_options()
54-
55-
# Set options (works as context manager)
56-
with config.set_options(label_include_units=False):
57-
fig = xpx(da).line()
58-
```
59-
60-
For all other visual customization (themes, colors, default template, etc.),
61-
use Plotly's built-in configuration via `plotly.io`:
62-
63-
```python
64-
import plotly.io as pio
65-
66-
pio.templates.default = "plotly_white"
67-
pio.renderers.default = "notebook"
68-
```
69-
70-
See [Plotly Templates](https://plotly.com/python/templates/) for available options.
71-
7237
::: xarray_plotly.config
7338
options:
7439
show_root_heading: true

docs/index.md

Lines changed: 23 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -2,89 +2,43 @@
22

33
**Interactive Plotly Express plotting accessor for xarray**
44

5-
xarray_plotly provides interactive plotting for xarray DataArray objects using Plotly Express. It automatically assigns dimensions to plot slots based on their order, making it easy to create rich, interactive visualizations with minimal code.
5+
::: xarray_plotly
6+
options:
7+
show_root_heading: false
8+
show_docstring_description: true
9+
show_docstring_examples: true
10+
members: false
611

7-
## Features
12+
## Installation
813

9-
- **Interactive plots**: Zoom, pan, hover for values, toggle traces - all built-in
10-
- **Automatic dimension assignment**: Dimensions fill plot slots (x, color, facet_col, etc.) by position
11-
- **Easy customization**: Returns Plotly `Figure` objects for further modification
12-
- **Multiple plot types**: Line, bar, area, scatter, box, and heatmap plots
13-
- **Faceting and animation**: Built-in support for subplot grids and animated time series
14-
- **Full IDE support**: The `xpx()` function provides complete code completion and type hints
14+
```bash
15+
pip install xarray_plotly
16+
```
1517

16-
## Quick Example
18+
## Usage
1719

1820
```python
1921
import xarray as xr
2022
import numpy as np
21-
from xarray_plotly import xpx
23+
import xarray_plotly # registers the accessor
2224

23-
# Create sample data
2425
da = xr.DataArray(
25-
np.random.randn(100, 3, 2),
26-
dims=["time", "city", "scenario"],
27-
coords={
28-
"time": np.arange(100),
29-
"city": ["NYC", "LA", "Chicago"],
30-
"scenario": ["baseline", "warming"],
31-
},
32-
name="temperature",
26+
np.random.randn(100, 3).cumsum(axis=0),
27+
dims=["time", "city"],
28+
coords={"time": np.arange(100), "city": ["NYC", "LA", "Chicago"]},
3329
)
3430

35-
# Create an interactive line plot
36-
# Dimensions auto-assign: time->x, city->color, scenario->facet_col
37-
fig = xpx(da).line()
38-
fig.show()
39-
40-
# Easy customization
41-
fig.update_layout(
42-
title="Temperature Projections",
43-
template="plotly_dark",
44-
)
45-
```
46-
47-
## Usage Styles
48-
49-
xarray_plotly supports two equivalent usage styles:
31+
# Accessor style
32+
fig = da.plotly.line()
5033

51-
```python
52-
# Function style (recommended) - full IDE code completion
34+
# Or with xpx() for IDE code completion
5335
from xarray_plotly import xpx
5436
fig = xpx(da).line()
55-
56-
# Accessor style - works but no IDE completion
57-
import xarray_plotly
58-
fig = da.plotly.line()
5937
```
6038

61-
The `xpx()` function is recommended as it provides full IDE code completion and type hints.
62-
63-
**Why no IDE completion for the accessor?** xarray accessors are registered dynamically at runtime using `register_dataarray_accessor()`. Python's static type checkers and IDEs cannot see these dynamically added attributes, so `da.plotly` appears as an unknown attribute. This limitation could only be solved by xarray itself (e.g., through a type checker plugin), if at all. The `xpx()` function provides a workaround with an explicit return type that IDEs can follow.
64-
65-
## Installation
66-
67-
```bash
68-
pip install xarray_plotly
69-
```
70-
71-
Or with uv:
72-
73-
```bash
74-
uv add xarray_plotly
75-
```
76-
77-
## Why xarray_plotly?
78-
79-
The current `.plot` accessor in xarray is built on matplotlib, which has limitations for modern data exploration:
80-
81-
1. **Static outputs**: Matplotlib plots are non-interactive
82-
2. **Post-creation modification is cumbersome**: Requires understanding complex object hierarchies
83-
3. **Multi-dimensional data**: No built-in support for faceting or animation
84-
85-
xarray_plotly solves these with Plotly Express, providing:
39+
## Next Steps
8640

87-
- Interactive plots with zero additional code
88-
- Simple, predictable dimension-to-slot assignment
89-
- Easy post-creation customization via Plotly's `Figure` API
90-
- Modern visualization patterns (faceting, animation) built-in
41+
- [Getting Started](getting-started.ipynb) - Interactive tutorial
42+
- [Plot Types](examples/plot-types.ipynb) - All available plot types
43+
- [Advanced Usage](examples/advanced.ipynb) - Configuration and customization
44+
- [API Reference](api.md) - Full API documentation

xarray_plotly/__init__.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,28 @@
11
"""
22
xarray_plotly: Interactive Plotly Express plotting for xarray.
33
4-
This package provides interactive plotting for xarray DataArray objects
5-
using Plotly Express.
4+
This package provides a `plotly` accessor for xarray DataArray objects,
5+
enabling interactive visualization with Plotly Express.
6+
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::
18+
19+
import xarray_plotly
20+
fig = da.plotly.line()
21+
22+
Function style (recommended for IDE completion)::
23+
24+
from xarray_plotly import xpx
25+
fig = xpx(da).line()
626
727
Examples
828
--------
@@ -21,8 +41,8 @@
2141
>>> # Explicit assignment
2242
>>> fig = xpx(da).line(x="time", color="scenario", facet_col="city")
2343
24-
>>> # Skip a slot
25-
>>> fig = xpx(da).line(color=None) # time->x, city->facet_col, scenario->facet_row
44+
>>> # Skip a slot with None
45+
>>> fig = xpx(da).line(color=None)
2646
"""
2747

2848
from importlib.metadata import version

xarray_plotly/accessor.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,40 @@
1313

1414
class DataArrayPlotlyAccessor:
1515
"""
16-
Enables use of Plotly Express plotting functions on a DataArray.
16+
Plotly Express plotting accessor for xarray DataArray.
1717
18-
Methods return Plotly Figure objects for interactive visualization.
18+
Dimensions are automatically assigned to plot slots by position.
19+
All methods return Plotly Figure objects for interactive visualization.
20+
21+
Available methods: line, bar, area, scatter, box, imshow
22+
23+
Parameters
24+
----------
25+
darray : DataArray
26+
The DataArray to plot.
1927
2028
Examples
2129
--------
2230
>>> import xarray as xr
2331
>>> import numpy as np
2432
>>> da = xr.DataArray(np.random.rand(10, 3), dims=["time", "city"])
25-
>>> fig = da.plotly.line() # Auto-assign dims: time->x, city->color
26-
>>> fig.show()
2733
28-
>>> fig = da.plotly.line(x="time", color=None) # Explicit assignment
29-
>>> fig.update_layout(title="My Plot")
34+
Auto-assign dimensions to slots:
35+
36+
>>> fig = da.plotly.line() # time->x, city->color
37+
38+
Explicit slot assignment:
39+
40+
>>> fig = da.plotly.line(color="time", x="city")
41+
42+
Skip a slot with None:
43+
44+
>>> fig = da.plotly.line(color=None) # time->x, city->line_dash
45+
46+
Customize the returned Figure:
47+
48+
>>> fig = da.plotly.line()
49+
>>> fig.update_layout(title="My Plot", template="plotly_dark")
3050
"""
3151

3252
__all__: ClassVar = ["line", "bar", "area", "scatter", "box", "imshow"]

xarray_plotly/common.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,17 @@ def assign_slots(
8181
ValueError
8282
If plot_type is unknown, a dimension doesn't exist, or dimensions
8383
are left unassigned (unless allow_unassigned=True).
84+
85+
Examples
86+
--------
87+
>>> assign_slots(["time", "city", "scenario"], "line")
88+
{'x': 'time', 'color': 'city', 'line_dash': 'scenario'}
89+
90+
>>> assign_slots(["time", "city"], "line", color="time", x="city")
91+
{'x': 'city', 'color': 'time'}
92+
93+
>>> assign_slots(["time", "city", "scenario"], "line", color=None)
94+
{'x': 'time', 'line_dash': 'city', 'symbol': 'scenario'}
8495
"""
8596
slot_orders = _options.slot_orders
8697
if plot_type not in slot_orders:

0 commit comments

Comments
 (0)