Skip to content

Commit 213801d

Browse files
committed
Add docs
1 parent 1471e3f commit 213801d

File tree

1 file changed

+10
-101
lines changed

1 file changed

+10
-101
lines changed

README.md

Lines changed: 10 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,133 +1,42 @@
11
# xarray_plotly
22

3-
**Interactive Plotly Express plotting accessor for xarray**
3+
**Interactive Plotly Express plotting for xarray**
44

55
[![PyPI version](https://badge.fury.io/py/xarray_plotly.svg)](https://badge.fury.io/py/xarray_plotly)
66
[![Python](https://img.shields.io/pypi/pyversions/xarray_plotly.svg)](https://pypi.org/project/xarray_plotly/)
7-
8-
xarray_plotly provides a `plotly` accessor for xarray DataArray objects that enables interactive plotting using Plotly Express with automatic dimension-to-slot assignment.
7+
[![Docs](https://img.shields.io/badge/docs-fbumann.github.io-blue)](https://fbumann.github.io/xarray_plotly/)
98

109
## Installation
1110

1211
```bash
1312
pip install xarray_plotly
1413
```
1514

16-
Or with uv:
17-
18-
```bash
19-
uv add xarray_plotly
20-
```
21-
2215
## Quick Start
2316

2417
```python
2518
import xarray as xr
2619
import numpy as np
27-
from xarray_plotly import xpx
20+
import xarray_plotly # registers the accessor
2821

29-
# Create sample data
3022
da = xr.DataArray(
31-
np.random.randn(100, 3, 2).cumsum(axis=0),
32-
dims=["time", "city", "scenario"],
33-
coords={
34-
"time": np.arange(100),
35-
"city": ["NYC", "LA", "Chicago"],
36-
"scenario": ["baseline", "warming"],
37-
},
38-
name="temperature",
23+
np.random.randn(100, 3).cumsum(axis=0),
24+
dims=["time", "city"],
25+
coords={"time": np.arange(100), "city": ["NYC", "LA", "Chicago"]},
3926
)
4027

41-
# Create an interactive line plot
42-
# Dimensions auto-assign: time→x, city→color, scenario→facet_col
43-
fig = xpx(da).line()
28+
# Accessor style
29+
fig = da.plotly.line()
4430
fig.show()
4531

46-
# Easy customization
47-
fig.update_layout(title="Temperature Projections", template="plotly_dark")
48-
```
49-
50-
## Usage Styles
51-
52-
xarray_plotly supports two equivalent usage styles:
53-
54-
```python
55-
# Function style (recommended) - full IDE code completion
32+
# Or with xpx() for IDE code completion
5633
from xarray_plotly import xpx
5734
fig = xpx(da).line()
58-
59-
# Accessor style - works but no IDE completion
60-
import xarray_plotly
61-
fig = da.plotly.line()
6235
```
6336

64-
The `xpx()` function is recommended as it provides full IDE code completion and type hints.
65-
66-
**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.
67-
68-
## Features
69-
70-
- **Interactive plots**: Zoom, pan, hover for values, toggle traces
71-
- **Automatic dimension assignment**: Dimensions fill plot slots by position
72-
- **Easy customization**: Returns Plotly `Figure` objects
73-
- **Multiple plot types**: `line()`, `bar()`, `area()`, `scatter()`, `box()`, `imshow()`
74-
- **Faceting and animation**: Built-in support for subplot grids and animations
75-
76-
## Dimension Assignment
77-
78-
Dimensions are automatically assigned to plot "slots" based on their order:
79-
80-
```python
81-
# dims: (time, city, scenario)
82-
# auto-assigns: time→x, city→color, scenario→facet_col
83-
xpx(da).line()
84-
85-
# Override with explicit assignments
86-
xpx(da).line(x="time", color="scenario", facet_col="city")
87-
88-
# Skip a slot with None
89-
xpx(da).line(color=None) # time→x, city→facet_col
90-
```
91-
92-
## Available Methods
93-
94-
| Method | Description | Slot Order |
95-
|--------|-------------|------------|
96-
| `line()` | Line plot | x → color → line_dash → symbol → facet_col → facet_row → animation_frame |
97-
| `bar()` | Bar chart | x → color → pattern_shape → facet_col → facet_row → animation_frame |
98-
| `area()` | Stacked area | x → color → pattern_shape → facet_col → facet_row → animation_frame |
99-
| `scatter()` | Scatter plot | x → color → symbol → facet_col → facet_row → animation_frame |
100-
| `box()` | Box plot | x → color → facet_col → facet_row → animation_frame |
101-
| `imshow()` | Heatmap | y → x → facet_col → animation_frame |
102-
103-
## Configuration
104-
105-
Customize label extraction and slot assignment behavior:
106-
107-
```python
108-
from xarray_plotly import config, xpx
109-
110-
# View current options
111-
config.get_options()
112-
113-
# Set globally (temporary)
114-
with config.set_options(label_include_units=False):
115-
fig = xpx(da).line() # Labels won't include units
116-
```
117-
118-
**Available options:**
119-
120-
| Option | Default | Description |
121-
|--------|---------|-------------|
122-
| `label_use_long_name` | `True` | Use `long_name` attr for labels |
123-
| `label_use_standard_name` | `True` | Fall back to `standard_name` |
124-
| `label_include_units` | `True` | Append units to labels |
125-
| `label_unit_format` | `"[{units}]"` | Format string for units |
126-
| `slot_orders` | (defaults) | Slot orders per plot type |
127-
12837
## Documentation
12938

130-
Full documentation with examples: [https://fbumann.github.io/xarray_plotly](https://fbumann.github.io/xarray_plotly)
39+
Full documentation: [https://fbumann.github.io/xarray_plotly](https://fbumann.github.io/xarray_plotly)
13140

13241
## License
13342

0 commit comments

Comments
 (0)