xarray-plotly 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. xarray_plotly-0.0.1/.github/workflows/ci.yml +42 -0
  2. xarray_plotly-0.0.1/.github/workflows/docs.yml +32 -0
  3. xarray_plotly-0.0.1/.github/workflows/release.yml +31 -0
  4. xarray_plotly-0.0.1/.gitignore +212 -0
  5. xarray_plotly-0.0.1/.pre-commit-config.yaml +22 -0
  6. xarray_plotly-0.0.1/CONTRIBUTING.md +52 -0
  7. xarray_plotly-0.0.1/LICENSE +21 -0
  8. xarray_plotly-0.0.1/PKG-INFO +175 -0
  9. xarray_plotly-0.0.1/README.md +134 -0
  10. xarray_plotly-0.0.1/docs/api.md +90 -0
  11. xarray_plotly-0.0.1/docs/examples/advanced.ipynb +425 -0
  12. xarray_plotly-0.0.1/docs/examples/plot-types.ipynb +381 -0
  13. xarray_plotly-0.0.1/docs/getting-started.ipynb +256 -0
  14. xarray_plotly-0.0.1/docs/index.md +90 -0
  15. xarray_plotly-0.0.1/mkdocs.yml +73 -0
  16. xarray_plotly-0.0.1/pyproject.toml +123 -0
  17. xarray_plotly-0.0.1/setup.cfg +4 -0
  18. xarray_plotly-0.0.1/tests/__init__.py +0 -0
  19. xarray_plotly-0.0.1/tests/test_accessor.py +208 -0
  20. xarray_plotly-0.0.1/tests/test_common.py +128 -0
  21. xarray_plotly-0.0.1/tests/test_config.py +188 -0
  22. xarray_plotly-0.0.1/xarray_plotly/__init__.py +73 -0
  23. xarray_plotly-0.0.1/xarray_plotly/accessor.py +336 -0
  24. xarray_plotly-0.0.1/xarray_plotly/common.py +247 -0
  25. xarray_plotly-0.0.1/xarray_plotly/config.py +203 -0
  26. xarray_plotly-0.0.1/xarray_plotly/plotting.py +448 -0
  27. xarray_plotly-0.0.1/xarray_plotly/py.typed +0 -0
  28. xarray_plotly-0.0.1/xarray_plotly.egg-info/PKG-INFO +175 -0
  29. xarray_plotly-0.0.1/xarray_plotly.egg-info/SOURCES.txt +30 -0
  30. xarray_plotly-0.0.1/xarray_plotly.egg-info/dependency_links.txt +1 -0
  31. xarray_plotly-0.0.1/xarray_plotly.egg-info/requires.txt +18 -0
  32. xarray_plotly-0.0.1/xarray_plotly.egg-info/top_level.txt +1 -0
@@ -0,0 +1,42 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ python-version: ["3.10", "3.11", "3.12", "3.13"]
15
+
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+
19
+ - name: Install uv
20
+ uses: astral-sh/setup-uv@v4
21
+
22
+ - name: Set up Python ${{ matrix.python-version }}
23
+ run: uv python install ${{ matrix.python-version }}
24
+
25
+ - name: Install dependencies
26
+ run: uv sync --extra dev
27
+
28
+ - name: Lint
29
+ run: uv run ruff check .
30
+
31
+ - name: Format check
32
+ run: uv run ruff format --check .
33
+
34
+ - name: Test
35
+ run: uv run pytest --cov=xarray_plotly --cov-report=xml
36
+
37
+ - name: Upload coverage
38
+ uses: codecov/codecov-action@v4
39
+ if: matrix.python-version == '3.12'
40
+ with:
41
+ token: ${{ secrets.CODECOV_TOKEN }}
42
+ fail_ci_if_error: false
@@ -0,0 +1,32 @@
1
+ name: Docs
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ release:
7
+ types: [published]
8
+
9
+ permissions:
10
+ contents: write
11
+
12
+ jobs:
13
+ docs:
14
+ runs-on: ubuntu-latest
15
+
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+
19
+ - name: Install uv
20
+ uses: astral-sh/setup-uv@v4
21
+
22
+ - name: Install dependencies
23
+ run: uv sync --extra docs
24
+
25
+ - name: Build docs
26
+ run: uv run mkdocs build
27
+
28
+ - name: Deploy to GitHub Pages
29
+ uses: peaceiris/actions-gh-pages@v4
30
+ with:
31
+ github_token: ${{ secrets.GITHUB_TOKEN }}
32
+ publish_dir: ./site
@@ -0,0 +1,31 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - "v*"
7
+
8
+ jobs:
9
+ release:
10
+ runs-on: ubuntu-latest
11
+ permissions:
12
+ id-token: write # for trusted publishing
13
+ contents: write # for creating GitHub release
14
+
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+
18
+ - name: Install uv
19
+ uses: astral-sh/setup-uv@v4
20
+
21
+ - name: Build package
22
+ run: uv build
23
+
24
+ - name: Publish to PyPI
25
+ uses: pypa/gh-action-pypi-publish@release/v1
26
+
27
+ - name: Create GitHub Release
28
+ uses: softprops/action-gh-release@v2
29
+ with:
30
+ generate_release_notes: true
31
+ files: dist/*
@@ -0,0 +1,212 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py.cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ #uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ #poetry.lock
109
+ #poetry.toml
110
+
111
+ # pdm
112
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
113
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
114
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
115
+ #pdm.lock
116
+ #pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # pixi
121
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
122
+ #pixi.lock
123
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
124
+ # in the .venv directory. It is recommended not to include this directory in version control.
125
+ .pixi
126
+
127
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
128
+ __pypackages__/
129
+
130
+ # Celery stuff
131
+ celerybeat-schedule
132
+ celerybeat.pid
133
+
134
+ # SageMath parsed files
135
+ *.sage.py
136
+
137
+ # Environments
138
+ .env
139
+ .envrc
140
+ .venv
141
+ env/
142
+ venv/
143
+ ENV/
144
+ env.bak/
145
+ venv.bak/
146
+
147
+ # Spyder project settings
148
+ .spyderproject
149
+ .spyproject
150
+
151
+ # Rope project settings
152
+ .ropeproject
153
+
154
+ # mkdocs documentation
155
+ /site
156
+
157
+ # mypy
158
+ .mypy_cache/
159
+ .dmypy.json
160
+ dmypy.json
161
+
162
+ # Pyre type checker
163
+ .pyre/
164
+
165
+ # pytype static type analyzer
166
+ .pytype/
167
+
168
+ # Cython debug symbols
169
+ cython_debug/
170
+
171
+ # PyCharm
172
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
173
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
174
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
175
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
176
+ .idea/
177
+
178
+ # Abstra
179
+ # Abstra is an AI-powered process automation framework.
180
+ # Ignore directories containing user credentials, local state, and settings.
181
+ # Learn more at https://abstra.io/docs
182
+ .abstra/
183
+
184
+ # Visual Studio Code
185
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
186
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
187
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
188
+ # you could uncomment the following to ignore the entire vscode folder
189
+ # .vscode/
190
+
191
+ # Ruff stuff:
192
+ .ruff_cache/
193
+
194
+ # PyPI configuration file
195
+ .pypirc
196
+
197
+ # Cursor
198
+ # Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
199
+ # exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
200
+ # refer to https://docs.cursor.com/context/ignore-files
201
+ .cursorignore
202
+ .cursorindexingignore
203
+
204
+ # Marimo
205
+ marimo/_static/
206
+ marimo/_lsp/
207
+ __marimo__/
208
+
209
+ _sketches/
210
+
211
+ uv.lock
212
+ .python-version
@@ -0,0 +1,22 @@
1
+ repos:
2
+ - repo: https://github.com/pre-commit/pre-commit-hooks
3
+ rev: v4.6.0
4
+ hooks:
5
+ - id: trailing-whitespace
6
+ - id: end-of-file-fixer
7
+ - id: check-yaml
8
+ args: [--unsafe]
9
+ - id: check-added-large-files
10
+ - id: check-toml
11
+
12
+ - repo: https://github.com/astral-sh/ruff-pre-commit
13
+ rev: v0.8.6
14
+ hooks:
15
+ - id: ruff
16
+ args: [--fix]
17
+ - id: ruff-format
18
+
19
+ - repo: https://github.com/kynan/nbstripout
20
+ rev: 0.7.1
21
+ hooks:
22
+ - id: nbstripout
@@ -0,0 +1,52 @@
1
+ # Contributing to xarray_plotly
2
+
3
+ Thanks for your interest in contributing!
4
+
5
+ ## Development Setup
6
+
7
+ ```bash
8
+ # Clone the repo
9
+ git clone https://github.com/FBumann/xarray_plotly.git
10
+ cd xarray_plotly
11
+
12
+ # Install with dev dependencies
13
+ uv sync --extra dev
14
+
15
+ # Install pre-commit hooks
16
+ uv run pre-commit install
17
+ ```
18
+
19
+ ## Running Tests
20
+
21
+ ```bash
22
+ uv run pytest
23
+ ```
24
+
25
+ ## Code Style
26
+
27
+ We use [ruff](https://github.com/astral-sh/ruff) for linting and formatting. Pre-commit hooks will run automatically, or you can run manually:
28
+
29
+ ```bash
30
+ uv run ruff check --fix .
31
+ uv run ruff format .
32
+ ```
33
+
34
+ ## Making Changes
35
+
36
+ 1. Fork the repository
37
+ 2. Create a feature branch (`git checkout -b feature/my-feature`)
38
+ 3. Make your changes
39
+ 4. Run tests (`uv run pytest`)
40
+ 5. Commit your changes
41
+ 6. Push to your fork and open a Pull Request
42
+
43
+ ## Releases
44
+
45
+ Releases are automated via GitHub Actions. Version is determined from git tags via setuptools_scm.
46
+
47
+ To create a release:
48
+
49
+ 1. Tag: `git tag v0.1.0`
50
+ 2. Push: `git push && git push --tags`
51
+
52
+ The CI will automatically publish to PyPI and deploy updated docs.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 FBumann
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,175 @@
1
+ Metadata-Version: 2.4
2
+ Name: xarray_plotly
3
+ Version: 0.0.1
4
+ Summary: Interactive Plotly Express plotting accessor for xarray
5
+ Author: Felix
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/FBumann/xarray_plotly
8
+ Project-URL: Documentation, https://fbumann.github.io/xarray_plotly
9
+ Project-URL: Repository, https://github.com/FBumann/xarray_plotly
10
+ Keywords: xarray,plotly,visualization,interactive,plotting
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Topic :: Scientific/Engineering :: Visualization
21
+ Requires-Python: >=3.10
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Requires-Dist: xarray>=2023.1.0
25
+ Requires-Dist: plotly>=5.0.0
26
+ Requires-Dist: pandas>=1.5.0
27
+ Provides-Extra: dev
28
+ Requires-Dist: pytest>=7.0; extra == "dev"
29
+ Requires-Dist: pytest-cov>=4.0; extra == "dev"
30
+ Requires-Dist: mypy>=1.0; extra == "dev"
31
+ Requires-Dist: ruff>=0.4; extra == "dev"
32
+ Requires-Dist: pre-commit>=3.0; extra == "dev"
33
+ Requires-Dist: nbstripout>=0.6; extra == "dev"
34
+ Provides-Extra: docs
35
+ Requires-Dist: mkdocs>=1.5; extra == "docs"
36
+ Requires-Dist: mkdocs-material>=9.0; extra == "docs"
37
+ Requires-Dist: mkdocstrings[python]>=0.24; extra == "docs"
38
+ Requires-Dist: mkdocs-jupyter>=0.24; extra == "docs"
39
+ Requires-Dist: mkdocs-plotly-plugin>=0.1; extra == "docs"
40
+ Dynamic: license-file
41
+
42
+ # xarray_plotly
43
+
44
+ **Interactive Plotly Express plotting accessor for xarray**
45
+
46
+ [![PyPI version](https://badge.fury.io/py/xarray_plotly.svg)](https://badge.fury.io/py/xarray_plotly)
47
+ [![Python](https://img.shields.io/pypi/pyversions/xarray_plotly.svg)](https://pypi.org/project/xarray_plotly/)
48
+
49
+ xarray_plotly provides a `plotly` accessor for xarray DataArray objects that enables interactive plotting using Plotly Express with automatic dimension-to-slot assignment.
50
+
51
+ ## Installation
52
+
53
+ ```bash
54
+ pip install xarray_plotly
55
+ ```
56
+
57
+ Or with uv:
58
+
59
+ ```bash
60
+ uv add xarray_plotly
61
+ ```
62
+
63
+ ## Quick Start
64
+
65
+ ```python
66
+ import xarray as xr
67
+ import numpy as np
68
+ from xarray_plotly import xpx
69
+
70
+ # Create sample data
71
+ da = xr.DataArray(
72
+ np.random.randn(100, 3, 2).cumsum(axis=0),
73
+ dims=["time", "city", "scenario"],
74
+ coords={
75
+ "time": np.arange(100),
76
+ "city": ["NYC", "LA", "Chicago"],
77
+ "scenario": ["baseline", "warming"],
78
+ },
79
+ name="temperature",
80
+ )
81
+
82
+ # Create an interactive line plot
83
+ # Dimensions auto-assign: time→x, city→color, scenario→facet_col
84
+ fig = xpx(da).line()
85
+ fig.show()
86
+
87
+ # Easy customization
88
+ fig.update_layout(title="Temperature Projections", template="plotly_dark")
89
+ ```
90
+
91
+ ## Usage Styles
92
+
93
+ xarray_plotly supports two equivalent usage styles:
94
+
95
+ ```python
96
+ # Function style (recommended) - full IDE code completion
97
+ from xarray_plotly import xpx
98
+ fig = xpx(da).line()
99
+
100
+ # Accessor style - works but no IDE completion
101
+ import xarray_plotly
102
+ fig = da.plotly.line()
103
+ ```
104
+
105
+ The `xpx()` function is recommended as it provides full IDE code completion and type hints.
106
+
107
+ **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.
108
+
109
+ ## Features
110
+
111
+ - **Interactive plots**: Zoom, pan, hover for values, toggle traces
112
+ - **Automatic dimension assignment**: Dimensions fill plot slots by position
113
+ - **Easy customization**: Returns Plotly `Figure` objects
114
+ - **Multiple plot types**: `line()`, `bar()`, `area()`, `scatter()`, `box()`, `imshow()`
115
+ - **Faceting and animation**: Built-in support for subplot grids and animations
116
+
117
+ ## Dimension Assignment
118
+
119
+ Dimensions are automatically assigned to plot "slots" based on their order:
120
+
121
+ ```python
122
+ # dims: (time, city, scenario)
123
+ # auto-assigns: time→x, city→color, scenario→facet_col
124
+ xpx(da).line()
125
+
126
+ # Override with explicit assignments
127
+ xpx(da).line(x="time", color="scenario", facet_col="city")
128
+
129
+ # Skip a slot with None
130
+ xpx(da).line(color=None) # time→x, city→facet_col
131
+ ```
132
+
133
+ ## Available Methods
134
+
135
+ | Method | Description | Slot Order |
136
+ |--------|-------------|------------|
137
+ | `line()` | Line plot | x → color → line_dash → symbol → facet_col → facet_row → animation_frame |
138
+ | `bar()` | Bar chart | x → color → pattern_shape → facet_col → facet_row → animation_frame |
139
+ | `area()` | Stacked area | x → color → pattern_shape → facet_col → facet_row → animation_frame |
140
+ | `scatter()` | Scatter plot | x → color → symbol → facet_col → facet_row → animation_frame |
141
+ | `box()` | Box plot | x → color → facet_col → facet_row → animation_frame |
142
+ | `imshow()` | Heatmap | y → x → facet_col → animation_frame |
143
+
144
+ ## Configuration
145
+
146
+ Customize label extraction and slot assignment behavior:
147
+
148
+ ```python
149
+ from xarray_plotly import config, xpx
150
+
151
+ # View current options
152
+ config.get_options()
153
+
154
+ # Set globally (temporary)
155
+ with config.set_options(label_include_units=False):
156
+ fig = xpx(da).line() # Labels won't include units
157
+ ```
158
+
159
+ **Available options:**
160
+
161
+ | Option | Default | Description |
162
+ |--------|---------|-------------|
163
+ | `label_use_long_name` | `True` | Use `long_name` attr for labels |
164
+ | `label_use_standard_name` | `True` | Fall back to `standard_name` |
165
+ | `label_include_units` | `True` | Append units to labels |
166
+ | `label_unit_format` | `"[{units}]"` | Format string for units |
167
+ | `slot_orders` | (defaults) | Slot orders per plot type |
168
+
169
+ ## Documentation
170
+
171
+ Full documentation with examples: [https://fbumann.github.io/xarray_plotly](https://fbumann.github.io/xarray_plotly)
172
+
173
+ ## License
174
+
175
+ MIT