xarray-plotly 0.0.13__py3-none-any.whl → 0.0.16__py3-none-any.whl
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.
- xarray_plotly/__init__.py +4 -0
- xarray_plotly/accessor.py +38 -3
- xarray_plotly/common.py +36 -3
- xarray_plotly/config.py +1 -1
- xarray_plotly/figures.py +525 -19
- xarray_plotly/plotting.py +69 -17
- {xarray_plotly-0.0.13.dist-info → xarray_plotly-0.0.16.dist-info}/METADATA +1 -15
- xarray_plotly-0.0.16.dist-info/RECORD +12 -0
- {xarray_plotly-0.0.13.dist-info → xarray_plotly-0.0.16.dist-info}/WHEEL +1 -1
- xarray_plotly-0.0.13.dist-info/RECORD +0 -12
- {xarray_plotly-0.0.13.dist-info → xarray_plotly-0.0.16.dist-info}/licenses/LICENSE +0 -0
- {xarray_plotly-0.0.13.dist-info → xarray_plotly-0.0.16.dist-info}/top_level.txt +0 -0
xarray_plotly/__init__.py
CHANGED
|
@@ -56,6 +56,8 @@ from xarray_plotly.common import SLOT_ORDERS, Colors, auto
|
|
|
56
56
|
from xarray_plotly.figures import (
|
|
57
57
|
add_secondary_y,
|
|
58
58
|
overlay,
|
|
59
|
+
simplify_facet_titles,
|
|
60
|
+
subplots,
|
|
59
61
|
update_traces,
|
|
60
62
|
)
|
|
61
63
|
|
|
@@ -66,6 +68,8 @@ __all__ = [
|
|
|
66
68
|
"auto",
|
|
67
69
|
"config",
|
|
68
70
|
"overlay",
|
|
71
|
+
"simplify_facet_titles",
|
|
72
|
+
"subplots",
|
|
69
73
|
"update_traces",
|
|
70
74
|
"xpx",
|
|
71
75
|
]
|
xarray_plotly/accessor.py
CHANGED
|
@@ -6,7 +6,7 @@ import plotly.graph_objects as go
|
|
|
6
6
|
from xarray import DataArray, Dataset
|
|
7
7
|
|
|
8
8
|
from xarray_plotly import plotting
|
|
9
|
-
from xarray_plotly.common import Colors, SlotValue, auto
|
|
9
|
+
from xarray_plotly.common import Colors, FacetTitlesMode, SlotValue, auto
|
|
10
10
|
from xarray_plotly.config import _options
|
|
11
11
|
|
|
12
12
|
|
|
@@ -54,6 +54,7 @@ class DataArrayPlotlyAccessor:
|
|
|
54
54
|
facet_row: SlotValue = auto,
|
|
55
55
|
animation_frame: SlotValue = auto,
|
|
56
56
|
colors: Colors = None,
|
|
57
|
+
facet_titles: FacetTitlesMode = "default",
|
|
57
58
|
**px_kwargs: Any,
|
|
58
59
|
) -> go.Figure:
|
|
59
60
|
"""Create an interactive line plot.
|
|
@@ -84,6 +85,7 @@ class DataArrayPlotlyAccessor:
|
|
|
84
85
|
facet_row=facet_row,
|
|
85
86
|
animation_frame=animation_frame,
|
|
86
87
|
colors=colors,
|
|
88
|
+
facet_titles=facet_titles,
|
|
87
89
|
**px_kwargs,
|
|
88
90
|
)
|
|
89
91
|
|
|
@@ -97,6 +99,7 @@ class DataArrayPlotlyAccessor:
|
|
|
97
99
|
facet_row: SlotValue = auto,
|
|
98
100
|
animation_frame: SlotValue = auto,
|
|
99
101
|
colors: Colors = None,
|
|
102
|
+
facet_titles: FacetTitlesMode = "default",
|
|
100
103
|
**px_kwargs: Any,
|
|
101
104
|
) -> go.Figure:
|
|
102
105
|
"""Create an interactive bar chart.
|
|
@@ -125,6 +128,7 @@ class DataArrayPlotlyAccessor:
|
|
|
125
128
|
facet_row=facet_row,
|
|
126
129
|
animation_frame=animation_frame,
|
|
127
130
|
colors=colors,
|
|
131
|
+
facet_titles=facet_titles,
|
|
128
132
|
**px_kwargs,
|
|
129
133
|
)
|
|
130
134
|
|
|
@@ -138,6 +142,7 @@ class DataArrayPlotlyAccessor:
|
|
|
138
142
|
facet_row: SlotValue = auto,
|
|
139
143
|
animation_frame: SlotValue = auto,
|
|
140
144
|
colors: Colors = None,
|
|
145
|
+
facet_titles: FacetTitlesMode = "default",
|
|
141
146
|
**px_kwargs: Any,
|
|
142
147
|
) -> go.Figure:
|
|
143
148
|
"""Create an interactive stacked area chart.
|
|
@@ -166,6 +171,7 @@ class DataArrayPlotlyAccessor:
|
|
|
166
171
|
facet_row=facet_row,
|
|
167
172
|
animation_frame=animation_frame,
|
|
168
173
|
colors=colors,
|
|
174
|
+
facet_titles=facet_titles,
|
|
169
175
|
**px_kwargs,
|
|
170
176
|
)
|
|
171
177
|
|
|
@@ -178,6 +184,7 @@ class DataArrayPlotlyAccessor:
|
|
|
178
184
|
facet_row: SlotValue = auto,
|
|
179
185
|
animation_frame: SlotValue = auto,
|
|
180
186
|
colors: Colors = None,
|
|
187
|
+
facet_titles: FacetTitlesMode = "default",
|
|
181
188
|
**px_kwargs: Any,
|
|
182
189
|
) -> go.Figure:
|
|
183
190
|
"""Create a bar-like chart using stacked areas for better performance.
|
|
@@ -204,6 +211,7 @@ class DataArrayPlotlyAccessor:
|
|
|
204
211
|
facet_row=facet_row,
|
|
205
212
|
animation_frame=animation_frame,
|
|
206
213
|
colors=colors,
|
|
214
|
+
facet_titles=facet_titles,
|
|
207
215
|
**px_kwargs,
|
|
208
216
|
)
|
|
209
217
|
|
|
@@ -218,6 +226,7 @@ class DataArrayPlotlyAccessor:
|
|
|
218
226
|
facet_row: SlotValue = auto,
|
|
219
227
|
animation_frame: SlotValue = auto,
|
|
220
228
|
colors: Colors = None,
|
|
229
|
+
facet_titles: FacetTitlesMode = "default",
|
|
221
230
|
**px_kwargs: Any,
|
|
222
231
|
) -> go.Figure:
|
|
223
232
|
"""Create an interactive scatter plot.
|
|
@@ -252,6 +261,7 @@ class DataArrayPlotlyAccessor:
|
|
|
252
261
|
facet_row=facet_row,
|
|
253
262
|
animation_frame=animation_frame,
|
|
254
263
|
colors=colors,
|
|
264
|
+
facet_titles=facet_titles,
|
|
255
265
|
**px_kwargs,
|
|
256
266
|
)
|
|
257
267
|
|
|
@@ -264,6 +274,7 @@ class DataArrayPlotlyAccessor:
|
|
|
264
274
|
facet_row: SlotValue = None,
|
|
265
275
|
animation_frame: SlotValue = None,
|
|
266
276
|
colors: Colors = None,
|
|
277
|
+
facet_titles: FacetTitlesMode = "default",
|
|
267
278
|
**px_kwargs: Any,
|
|
268
279
|
) -> go.Figure:
|
|
269
280
|
"""Create an interactive box plot.
|
|
@@ -293,6 +304,7 @@ class DataArrayPlotlyAccessor:
|
|
|
293
304
|
facet_row=facet_row,
|
|
294
305
|
animation_frame=animation_frame,
|
|
295
306
|
colors=colors,
|
|
307
|
+
facet_titles=facet_titles,
|
|
296
308
|
**px_kwargs,
|
|
297
309
|
)
|
|
298
310
|
|
|
@@ -302,14 +314,16 @@ class DataArrayPlotlyAccessor:
|
|
|
302
314
|
x: SlotValue = auto,
|
|
303
315
|
y: SlotValue = auto,
|
|
304
316
|
facet_col: SlotValue = auto,
|
|
317
|
+
facet_row: SlotValue = auto,
|
|
305
318
|
animation_frame: SlotValue = auto,
|
|
306
319
|
robust: bool = False,
|
|
307
320
|
colors: Colors = None,
|
|
321
|
+
facet_titles: FacetTitlesMode = "default",
|
|
308
322
|
**px_kwargs: Any,
|
|
309
323
|
) -> go.Figure:
|
|
310
324
|
"""Create an interactive heatmap image.
|
|
311
325
|
|
|
312
|
-
Slot order: y (rows) -> x (columns) -> facet_col -> animation_frame
|
|
326
|
+
Slot order: y (rows) -> x (columns) -> facet_col -> facet_row -> animation_frame
|
|
313
327
|
|
|
314
328
|
Note:
|
|
315
329
|
**Difference from px.imshow**: Color bounds are computed from the
|
|
@@ -320,7 +334,10 @@ class DataArrayPlotlyAccessor:
|
|
|
320
334
|
x: Dimension for x-axis (columns). Default: second dimension.
|
|
321
335
|
y: Dimension for y-axis (rows). Default: first dimension.
|
|
322
336
|
facet_col: Dimension for subplot columns. Default: third dimension.
|
|
323
|
-
|
|
337
|
+
facet_row: Dimension for subplot rows. Default: fourth dimension.
|
|
338
|
+
Requires plotly>=6.7.0; on older versions this slot is skipped
|
|
339
|
+
during auto-assignment.
|
|
340
|
+
animation_frame: Dimension for animation. Default: fifth dimension.
|
|
324
341
|
robust: If True, use 2nd/98th percentiles for color bounds (handles outliers).
|
|
325
342
|
colors: Color scale name (e.g., "Viridis", "RdBu"). See module docs.
|
|
326
343
|
**px_kwargs: Additional arguments passed to `plotly.express.imshow()`.
|
|
@@ -334,9 +351,11 @@ class DataArrayPlotlyAccessor:
|
|
|
334
351
|
x=x,
|
|
335
352
|
y=y,
|
|
336
353
|
facet_col=facet_col,
|
|
354
|
+
facet_row=facet_row,
|
|
337
355
|
animation_frame=animation_frame,
|
|
338
356
|
robust=robust,
|
|
339
357
|
colors=colors,
|
|
358
|
+
facet_titles=facet_titles,
|
|
340
359
|
**px_kwargs,
|
|
341
360
|
)
|
|
342
361
|
|
|
@@ -348,6 +367,7 @@ class DataArrayPlotlyAccessor:
|
|
|
348
367
|
facet_col: SlotValue = auto,
|
|
349
368
|
facet_row: SlotValue = auto,
|
|
350
369
|
colors: Colors = None,
|
|
370
|
+
facet_titles: FacetTitlesMode = "default",
|
|
351
371
|
**px_kwargs: Any,
|
|
352
372
|
) -> go.Figure:
|
|
353
373
|
"""Create an interactive pie chart.
|
|
@@ -372,6 +392,7 @@ class DataArrayPlotlyAccessor:
|
|
|
372
392
|
facet_col=facet_col,
|
|
373
393
|
facet_row=facet_row,
|
|
374
394
|
colors=colors,
|
|
395
|
+
facet_titles=facet_titles,
|
|
375
396
|
**px_kwargs,
|
|
376
397
|
)
|
|
377
398
|
|
|
@@ -452,6 +473,7 @@ class DatasetPlotlyAccessor:
|
|
|
452
473
|
facet_row: SlotValue = auto,
|
|
453
474
|
animation_frame: SlotValue = auto,
|
|
454
475
|
colors: Colors = None,
|
|
476
|
+
facet_titles: FacetTitlesMode = "default",
|
|
455
477
|
**px_kwargs: Any,
|
|
456
478
|
) -> go.Figure:
|
|
457
479
|
"""Create an interactive line plot.
|
|
@@ -482,6 +504,7 @@ class DatasetPlotlyAccessor:
|
|
|
482
504
|
facet_row=facet_row,
|
|
483
505
|
animation_frame=animation_frame,
|
|
484
506
|
colors=colors,
|
|
507
|
+
facet_titles=facet_titles,
|
|
485
508
|
**px_kwargs,
|
|
486
509
|
)
|
|
487
510
|
|
|
@@ -496,6 +519,7 @@ class DatasetPlotlyAccessor:
|
|
|
496
519
|
facet_row: SlotValue = auto,
|
|
497
520
|
animation_frame: SlotValue = auto,
|
|
498
521
|
colors: Colors = None,
|
|
522
|
+
facet_titles: FacetTitlesMode = "default",
|
|
499
523
|
**px_kwargs: Any,
|
|
500
524
|
) -> go.Figure:
|
|
501
525
|
"""Create an interactive bar chart.
|
|
@@ -524,6 +548,7 @@ class DatasetPlotlyAccessor:
|
|
|
524
548
|
facet_row=facet_row,
|
|
525
549
|
animation_frame=animation_frame,
|
|
526
550
|
colors=colors,
|
|
551
|
+
facet_titles=facet_titles,
|
|
527
552
|
**px_kwargs,
|
|
528
553
|
)
|
|
529
554
|
|
|
@@ -538,6 +563,7 @@ class DatasetPlotlyAccessor:
|
|
|
538
563
|
facet_row: SlotValue = auto,
|
|
539
564
|
animation_frame: SlotValue = auto,
|
|
540
565
|
colors: Colors = None,
|
|
566
|
+
facet_titles: FacetTitlesMode = "default",
|
|
541
567
|
**px_kwargs: Any,
|
|
542
568
|
) -> go.Figure:
|
|
543
569
|
"""Create an interactive stacked area chart.
|
|
@@ -566,6 +592,7 @@ class DatasetPlotlyAccessor:
|
|
|
566
592
|
facet_row=facet_row,
|
|
567
593
|
animation_frame=animation_frame,
|
|
568
594
|
colors=colors,
|
|
595
|
+
facet_titles=facet_titles,
|
|
569
596
|
**px_kwargs,
|
|
570
597
|
)
|
|
571
598
|
|
|
@@ -579,6 +606,7 @@ class DatasetPlotlyAccessor:
|
|
|
579
606
|
facet_row: SlotValue = auto,
|
|
580
607
|
animation_frame: SlotValue = auto,
|
|
581
608
|
colors: Colors = None,
|
|
609
|
+
facet_titles: FacetTitlesMode = "default",
|
|
582
610
|
**px_kwargs: Any,
|
|
583
611
|
) -> go.Figure:
|
|
584
612
|
"""Create a bar-like chart using stacked areas for better performance.
|
|
@@ -605,6 +633,7 @@ class DatasetPlotlyAccessor:
|
|
|
605
633
|
facet_row=facet_row,
|
|
606
634
|
animation_frame=animation_frame,
|
|
607
635
|
colors=colors,
|
|
636
|
+
facet_titles=facet_titles,
|
|
608
637
|
**px_kwargs,
|
|
609
638
|
)
|
|
610
639
|
|
|
@@ -620,6 +649,7 @@ class DatasetPlotlyAccessor:
|
|
|
620
649
|
facet_row: SlotValue = auto,
|
|
621
650
|
animation_frame: SlotValue = auto,
|
|
622
651
|
colors: Colors = None,
|
|
652
|
+
facet_titles: FacetTitlesMode = "default",
|
|
623
653
|
**px_kwargs: Any,
|
|
624
654
|
) -> go.Figure:
|
|
625
655
|
"""Create an interactive scatter plot.
|
|
@@ -650,6 +680,7 @@ class DatasetPlotlyAccessor:
|
|
|
650
680
|
facet_row=facet_row,
|
|
651
681
|
animation_frame=animation_frame,
|
|
652
682
|
colors=colors,
|
|
683
|
+
facet_titles=facet_titles,
|
|
653
684
|
**px_kwargs,
|
|
654
685
|
)
|
|
655
686
|
|
|
@@ -663,6 +694,7 @@ class DatasetPlotlyAccessor:
|
|
|
663
694
|
facet_row: SlotValue = None,
|
|
664
695
|
animation_frame: SlotValue = None,
|
|
665
696
|
colors: Colors = None,
|
|
697
|
+
facet_titles: FacetTitlesMode = "default",
|
|
666
698
|
**px_kwargs: Any,
|
|
667
699
|
) -> go.Figure:
|
|
668
700
|
"""Create an interactive box plot.
|
|
@@ -689,6 +721,7 @@ class DatasetPlotlyAccessor:
|
|
|
689
721
|
facet_row=facet_row,
|
|
690
722
|
animation_frame=animation_frame,
|
|
691
723
|
colors=colors,
|
|
724
|
+
facet_titles=facet_titles,
|
|
692
725
|
**px_kwargs,
|
|
693
726
|
)
|
|
694
727
|
|
|
@@ -701,6 +734,7 @@ class DatasetPlotlyAccessor:
|
|
|
701
734
|
facet_col: SlotValue = auto,
|
|
702
735
|
facet_row: SlotValue = auto,
|
|
703
736
|
colors: Colors = None,
|
|
737
|
+
facet_titles: FacetTitlesMode = "default",
|
|
704
738
|
**px_kwargs: Any,
|
|
705
739
|
) -> go.Figure:
|
|
706
740
|
"""Create an interactive pie chart.
|
|
@@ -725,5 +759,6 @@ class DatasetPlotlyAccessor:
|
|
|
725
759
|
facet_col=facet_col,
|
|
726
760
|
facet_row=facet_row,
|
|
727
761
|
colors=colors,
|
|
762
|
+
facet_titles=facet_titles,
|
|
728
763
|
**px_kwargs,
|
|
729
764
|
)
|
xarray_plotly/common.py
CHANGED
|
@@ -5,7 +5,7 @@ from __future__ import annotations
|
|
|
5
5
|
import functools
|
|
6
6
|
import warnings
|
|
7
7
|
from collections.abc import Hashable, Mapping, Sequence
|
|
8
|
-
from typing import TYPE_CHECKING, Any
|
|
8
|
+
from typing import TYPE_CHECKING, Any, Literal
|
|
9
9
|
|
|
10
10
|
import plotly.express as px
|
|
11
11
|
|
|
@@ -13,7 +13,7 @@ from xarray_plotly.config import DEFAULT_SLOT_ORDERS, _options
|
|
|
13
13
|
|
|
14
14
|
if TYPE_CHECKING:
|
|
15
15
|
import pandas as pd
|
|
16
|
-
from xarray import DataArray
|
|
16
|
+
from xarray import DataArray, Dataset
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
class _AUTO:
|
|
@@ -39,6 +39,13 @@ Colors = str | Sequence[str] | Mapping[str, str] | None
|
|
|
39
39
|
- None: Use Plotly defaults
|
|
40
40
|
"""
|
|
41
41
|
|
|
42
|
+
FacetTitlesMode = Literal["value", "default"]
|
|
43
|
+
"""Type alias for facet_titles parameter.
|
|
44
|
+
|
|
45
|
+
- "default" (default): keep PX's ``"<dim>=<value>"`` subplot titles.
|
|
46
|
+
- "value": strip the ``<dim>=`` prefix, leaving just the value.
|
|
47
|
+
"""
|
|
48
|
+
|
|
42
49
|
# Re-export for backward compatibility
|
|
43
50
|
SLOT_ORDERS = DEFAULT_SLOT_ORDERS
|
|
44
51
|
"""Slot orders per plot type.
|
|
@@ -251,7 +258,21 @@ def _get_qualitative_scale_names() -> frozenset[str]:
|
|
|
251
258
|
)
|
|
252
259
|
|
|
253
260
|
|
|
254
|
-
def
|
|
261
|
+
def _sample_colorscale(name: str, n: int) -> list[str]:
|
|
262
|
+
"""Sample *n* evenly-spaced colors from a named Plotly colorscale."""
|
|
263
|
+
scale = px.colors.get_colorscale(name)
|
|
264
|
+
samplepoints = [i / max(n - 1, 1) for i in range(n)]
|
|
265
|
+
result: list[str] = px.colors.sample_colorscale(scale, samplepoints)
|
|
266
|
+
return result
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
def resolve_colors(
|
|
270
|
+
colors: Colors,
|
|
271
|
+
px_kwargs: dict[str, Any],
|
|
272
|
+
*,
|
|
273
|
+
color_dim: Hashable | None = None,
|
|
274
|
+
darray: DataArray | Dataset | None = None,
|
|
275
|
+
) -> dict[str, Any]:
|
|
255
276
|
"""Map unified `colors` parameter to appropriate Plotly px_kwargs.
|
|
256
277
|
|
|
257
278
|
Direct color_* kwargs take precedence and trigger a warning if
|
|
@@ -260,6 +281,14 @@ def resolve_colors(colors: Colors, px_kwargs: dict[str, Any]) -> dict[str, Any]:
|
|
|
260
281
|
Args:
|
|
261
282
|
colors: Unified color specification (str, list, dict, or None).
|
|
262
283
|
px_kwargs: Existing kwargs to pass to Plotly Express.
|
|
284
|
+
color_dim: Dimension name used for discrete color grouping.
|
|
285
|
+
When provided together with *darray*, a continuous colorscale
|
|
286
|
+
string is sampled into a discrete sequence whose length
|
|
287
|
+
matches the number of coordinates along this dimension.
|
|
288
|
+
Use for chart types that only accept discrete color
|
|
289
|
+
parameters (line, area, box, pie).
|
|
290
|
+
darray: Source DataArray or Dataset; used with *color_dim* to
|
|
291
|
+
determine the number of discrete colors to sample.
|
|
263
292
|
|
|
264
293
|
Returns:
|
|
265
294
|
Updated px_kwargs with color parameters injected.
|
|
@@ -284,6 +313,10 @@ def resolve_colors(colors: Colors, px_kwargs: dict[str, Any]) -> dict[str, Any]:
|
|
|
284
313
|
# Check if it's a qualitative (discrete) palette name
|
|
285
314
|
if colors in _get_qualitative_scale_names():
|
|
286
315
|
px_kwargs["color_discrete_sequence"] = getattr(px.colors.qualitative, colors)
|
|
316
|
+
elif color_dim is not None and darray is not None:
|
|
317
|
+
# Sample from continuous scale into a discrete sequence
|
|
318
|
+
n = darray.sizes[color_dim]
|
|
319
|
+
px_kwargs["color_discrete_sequence"] = _sample_colorscale(colors, n)
|
|
287
320
|
else:
|
|
288
321
|
# Assume continuous scale
|
|
289
322
|
px_kwargs["color_continuous_scale"] = colors
|
xarray_plotly/config.py
CHANGED
|
@@ -43,7 +43,7 @@ DEFAULT_SLOT_ORDERS: dict[str, tuple[str, ...]] = {
|
|
|
43
43
|
"facet_row",
|
|
44
44
|
"animation_frame",
|
|
45
45
|
),
|
|
46
|
-
"imshow": ("y", "x", "facet_col", "animation_frame"),
|
|
46
|
+
"imshow": ("y", "x", "facet_col", "facet_row", "animation_frame"),
|
|
47
47
|
"box": ("x", "color", "facet_col", "facet_row", "animation_frame"),
|
|
48
48
|
"pie": ("names", "facet_col", "facet_row"),
|
|
49
49
|
}
|