Skip to content

Commit 8fdc7b0

Browse files
committed
Add new Colors and colors parameter to all methods
1 parent 9904fd3 commit 8fdc7b0

File tree

4 files changed

+191
-5
lines changed

4 files changed

+191
-5
lines changed

xarray_plotly/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252

5353
from xarray_plotly import config
5454
from xarray_plotly.accessor import DataArrayPlotlyAccessor, DatasetPlotlyAccessor
55-
from xarray_plotly.common import SLOT_ORDERS, auto
55+
from xarray_plotly.common import SLOT_ORDERS, Colors, auto
5656
from xarray_plotly.figures import (
5757
add_secondary_y,
5858
overlay,
@@ -61,6 +61,7 @@
6161

6262
__all__ = [
6363
"SLOT_ORDERS",
64+
"Colors",
6465
"add_secondary_y",
6566
"auto",
6667
"config",

xarray_plotly/accessor.py

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from xarray import DataArray, Dataset
77

88
from xarray_plotly import plotting
9-
from xarray_plotly.common import SlotValue, auto
9+
from xarray_plotly.common import Colors, SlotValue, auto
1010
from xarray_plotly.config import _options
1111

1212

@@ -53,6 +53,7 @@ def line(
5353
facet_col: SlotValue = auto,
5454
facet_row: SlotValue = auto,
5555
animation_frame: SlotValue = auto,
56+
colors: Colors = None,
5657
**px_kwargs: Any,
5758
) -> go.Figure:
5859
"""Create an interactive line plot.
@@ -67,6 +68,7 @@ def line(
6768
facet_col: Dimension for subplot columns. Default: fifth dimension.
6869
facet_row: Dimension for subplot rows. Default: sixth dimension.
6970
animation_frame: Dimension for animation. Default: seventh dimension.
71+
colors: Color specification (scale name, list, or dict). See module docs.
7072
**px_kwargs: Additional arguments passed to `plotly.express.line()`.
7173
7274
Returns:
@@ -81,6 +83,7 @@ def line(
8183
facet_col=facet_col,
8284
facet_row=facet_row,
8385
animation_frame=animation_frame,
86+
colors=colors,
8487
**px_kwargs,
8588
)
8689

@@ -93,6 +96,7 @@ def bar(
9396
facet_col: SlotValue = auto,
9497
facet_row: SlotValue = auto,
9598
animation_frame: SlotValue = auto,
99+
colors: Colors = None,
96100
**px_kwargs: Any,
97101
) -> go.Figure:
98102
"""Create an interactive bar chart.
@@ -106,6 +110,7 @@ def bar(
106110
facet_col: Dimension for subplot columns. Default: fourth dimension.
107111
facet_row: Dimension for subplot rows. Default: fifth dimension.
108112
animation_frame: Dimension for animation. Default: sixth dimension.
113+
colors: Color specification (scale name, list, or dict). See module docs.
109114
**px_kwargs: Additional arguments passed to `plotly.express.bar()`.
110115
111116
Returns:
@@ -119,6 +124,7 @@ def bar(
119124
facet_col=facet_col,
120125
facet_row=facet_row,
121126
animation_frame=animation_frame,
127+
colors=colors,
122128
**px_kwargs,
123129
)
124130

@@ -131,6 +137,7 @@ def area(
131137
facet_col: SlotValue = auto,
132138
facet_row: SlotValue = auto,
133139
animation_frame: SlotValue = auto,
140+
colors: Colors = None,
134141
**px_kwargs: Any,
135142
) -> go.Figure:
136143
"""Create an interactive stacked area chart.
@@ -144,6 +151,7 @@ def area(
144151
facet_col: Dimension for subplot columns. Default: fourth dimension.
145152
facet_row: Dimension for subplot rows. Default: fifth dimension.
146153
animation_frame: Dimension for animation. Default: sixth dimension.
154+
colors: Color specification (scale name, list, or dict). See module docs.
147155
**px_kwargs: Additional arguments passed to `plotly.express.area()`.
148156
149157
Returns:
@@ -157,6 +165,7 @@ def area(
157165
facet_col=facet_col,
158166
facet_row=facet_row,
159167
animation_frame=animation_frame,
168+
colors=colors,
160169
**px_kwargs,
161170
)
162171

@@ -168,6 +177,7 @@ def fast_bar(
168177
facet_col: SlotValue = auto,
169178
facet_row: SlotValue = auto,
170179
animation_frame: SlotValue = auto,
180+
colors: Colors = None,
171181
**px_kwargs: Any,
172182
) -> go.Figure:
173183
"""Create a bar-like chart using stacked areas for better performance.
@@ -180,6 +190,7 @@ def fast_bar(
180190
facet_col: Dimension for subplot columns. Default: third dimension.
181191
facet_row: Dimension for subplot rows. Default: fourth dimension.
182192
animation_frame: Dimension for animation. Default: fifth dimension.
193+
colors: Color specification (scale name, list, or dict). See module docs.
183194
**px_kwargs: Additional arguments passed to `plotly.express.area()`.
184195
185196
Returns:
@@ -192,6 +203,7 @@ def fast_bar(
192203
facet_col=facet_col,
193204
facet_row=facet_row,
194205
animation_frame=animation_frame,
206+
colors=colors,
195207
**px_kwargs,
196208
)
197209

@@ -205,6 +217,7 @@ def scatter(
205217
facet_col: SlotValue = auto,
206218
facet_row: SlotValue = auto,
207219
animation_frame: SlotValue = auto,
220+
colors: Colors = None,
208221
**px_kwargs: Any,
209222
) -> go.Figure:
210223
"""Create an interactive scatter plot.
@@ -223,6 +236,7 @@ def scatter(
223236
facet_col: Dimension for subplot columns. Default: fourth dimension.
224237
facet_row: Dimension for subplot rows. Default: fifth dimension.
225238
animation_frame: Dimension for animation. Default: sixth dimension.
239+
colors: Color specification (scale name, list, or dict). See module docs.
226240
**px_kwargs: Additional arguments passed to `plotly.express.scatter()`.
227241
228242
Returns:
@@ -237,6 +251,7 @@ def scatter(
237251
facet_col=facet_col,
238252
facet_row=facet_row,
239253
animation_frame=animation_frame,
254+
colors=colors,
240255
**px_kwargs,
241256
)
242257

@@ -248,6 +263,7 @@ def box(
248263
facet_col: SlotValue = None,
249264
facet_row: SlotValue = None,
250265
animation_frame: SlotValue = None,
266+
colors: Colors = None,
251267
**px_kwargs: Any,
252268
) -> go.Figure:
253269
"""Create an interactive box plot.
@@ -263,6 +279,7 @@ def box(
263279
facet_col: Dimension for subplot columns. Default: None (aggregated).
264280
facet_row: Dimension for subplot rows. Default: None (aggregated).
265281
animation_frame: Dimension for animation. Default: None (aggregated).
282+
colors: Color specification (scale name, list, or dict). See module docs.
266283
**px_kwargs: Additional arguments passed to `plotly.express.box()`.
267284
268285
Returns:
@@ -275,6 +292,7 @@ def box(
275292
facet_col=facet_col,
276293
facet_row=facet_row,
277294
animation_frame=animation_frame,
295+
colors=colors,
278296
**px_kwargs,
279297
)
280298

@@ -286,6 +304,7 @@ def imshow(
286304
facet_col: SlotValue = auto,
287305
animation_frame: SlotValue = auto,
288306
robust: bool = False,
307+
colors: Colors = None,
289308
**px_kwargs: Any,
290309
) -> go.Figure:
291310
"""Create an interactive heatmap image.
@@ -303,6 +322,7 @@ def imshow(
303322
facet_col: Dimension for subplot columns. Default: third dimension.
304323
animation_frame: Dimension for animation. Default: fourth dimension.
305324
robust: If True, use 2nd/98th percentiles for color bounds (handles outliers).
325+
colors: Color scale name (e.g., "Viridis", "RdBu"). See module docs.
306326
**px_kwargs: Additional arguments passed to `plotly.express.imshow()`.
307327
Use `zmin` and `zmax` to manually set color scale bounds.
308328
@@ -316,6 +336,7 @@ def imshow(
316336
facet_col=facet_col,
317337
animation_frame=animation_frame,
318338
robust=robust,
339+
colors=colors,
319340
**px_kwargs,
320341
)
321342

@@ -326,6 +347,7 @@ def pie(
326347
color: SlotValue = None,
327348
facet_col: SlotValue = auto,
328349
facet_row: SlotValue = auto,
350+
colors: Colors = None,
329351
**px_kwargs: Any,
330352
) -> go.Figure:
331353
"""Create an interactive pie chart.
@@ -337,6 +359,7 @@ def pie(
337359
color: Dimension for color grouping. Default: None (uses names).
338360
facet_col: Dimension for subplot columns. Default: second dimension.
339361
facet_row: Dimension for subplot rows. Default: third dimension.
362+
colors: Color specification (scale name, list, or dict). See module docs.
340363
**px_kwargs: Additional arguments passed to `plotly.express.pie()`.
341364
342365
Returns:
@@ -348,6 +371,7 @@ def pie(
348371
color=color,
349372
facet_col=facet_col,
350373
facet_row=facet_row,
374+
colors=colors,
351375
**px_kwargs,
352376
)
353377

@@ -427,6 +451,7 @@ def line(
427451
facet_col: SlotValue = auto,
428452
facet_row: SlotValue = auto,
429453
animation_frame: SlotValue = auto,
454+
colors: Colors = None,
430455
**px_kwargs: Any,
431456
) -> go.Figure:
432457
"""Create an interactive line plot.
@@ -440,6 +465,7 @@ def line(
440465
facet_col: Dimension for subplot columns.
441466
facet_row: Dimension for subplot rows.
442467
animation_frame: Dimension for animation.
468+
colors: Color specification (scale name, list, or dict). See module docs.
443469
**px_kwargs: Additional arguments passed to `plotly.express.line()`.
444470
445471
Returns:
@@ -455,6 +481,7 @@ def line(
455481
facet_col=facet_col,
456482
facet_row=facet_row,
457483
animation_frame=animation_frame,
484+
colors=colors,
458485
**px_kwargs,
459486
)
460487

@@ -468,6 +495,7 @@ def bar(
468495
facet_col: SlotValue = auto,
469496
facet_row: SlotValue = auto,
470497
animation_frame: SlotValue = auto,
498+
colors: Colors = None,
471499
**px_kwargs: Any,
472500
) -> go.Figure:
473501
"""Create an interactive bar chart.
@@ -480,6 +508,7 @@ def bar(
480508
facet_col: Dimension for subplot columns.
481509
facet_row: Dimension for subplot rows.
482510
animation_frame: Dimension for animation.
511+
colors: Color specification (scale name, list, or dict). See module docs.
483512
**px_kwargs: Additional arguments passed to `plotly.express.bar()`.
484513
485514
Returns:
@@ -494,6 +523,7 @@ def bar(
494523
facet_col=facet_col,
495524
facet_row=facet_row,
496525
animation_frame=animation_frame,
526+
colors=colors,
497527
**px_kwargs,
498528
)
499529

@@ -507,6 +537,7 @@ def area(
507537
facet_col: SlotValue = auto,
508538
facet_row: SlotValue = auto,
509539
animation_frame: SlotValue = auto,
540+
colors: Colors = None,
510541
**px_kwargs: Any,
511542
) -> go.Figure:
512543
"""Create an interactive stacked area chart.
@@ -519,6 +550,7 @@ def area(
519550
facet_col: Dimension for subplot columns.
520551
facet_row: Dimension for subplot rows.
521552
animation_frame: Dimension for animation.
553+
colors: Color specification (scale name, list, or dict). See module docs.
522554
**px_kwargs: Additional arguments passed to `plotly.express.area()`.
523555
524556
Returns:
@@ -533,6 +565,7 @@ def area(
533565
facet_col=facet_col,
534566
facet_row=facet_row,
535567
animation_frame=animation_frame,
568+
colors=colors,
536569
**px_kwargs,
537570
)
538571

@@ -545,6 +578,7 @@ def fast_bar(
545578
facet_col: SlotValue = auto,
546579
facet_row: SlotValue = auto,
547580
animation_frame: SlotValue = auto,
581+
colors: Colors = None,
548582
**px_kwargs: Any,
549583
) -> go.Figure:
550584
"""Create a bar-like chart using stacked areas for better performance.
@@ -556,6 +590,7 @@ def fast_bar(
556590
facet_col: Dimension for subplot columns.
557591
facet_row: Dimension for subplot rows.
558592
animation_frame: Dimension for animation.
593+
colors: Color specification (scale name, list, or dict). See module docs.
559594
**px_kwargs: Additional arguments passed to `plotly.express.area()`.
560595
561596
Returns:
@@ -569,6 +604,7 @@ def fast_bar(
569604
facet_col=facet_col,
570605
facet_row=facet_row,
571606
animation_frame=animation_frame,
607+
colors=colors,
572608
**px_kwargs,
573609
)
574610

@@ -583,6 +619,7 @@ def scatter(
583619
facet_col: SlotValue = auto,
584620
facet_row: SlotValue = auto,
585621
animation_frame: SlotValue = auto,
622+
colors: Colors = None,
586623
**px_kwargs: Any,
587624
) -> go.Figure:
588625
"""Create an interactive scatter plot.
@@ -596,6 +633,7 @@ def scatter(
596633
facet_col: Dimension for subplot columns.
597634
facet_row: Dimension for subplot rows.
598635
animation_frame: Dimension for animation.
636+
colors: Color specification (scale name, list, or dict). See module docs.
599637
**px_kwargs: Additional arguments passed to `plotly.express.scatter()`.
600638
601639
Returns:
@@ -611,6 +649,7 @@ def scatter(
611649
facet_col=facet_col,
612650
facet_row=facet_row,
613651
animation_frame=animation_frame,
652+
colors=colors,
614653
**px_kwargs,
615654
)
616655

@@ -623,6 +662,7 @@ def box(
623662
facet_col: SlotValue = None,
624663
facet_row: SlotValue = None,
625664
animation_frame: SlotValue = None,
665+
colors: Colors = None,
626666
**px_kwargs: Any,
627667
) -> go.Figure:
628668
"""Create an interactive box plot.
@@ -634,6 +674,7 @@ def box(
634674
facet_col: Dimension for subplot columns.
635675
facet_row: Dimension for subplot rows.
636676
animation_frame: Dimension for animation.
677+
colors: Color specification (scale name, list, or dict). See module docs.
637678
**px_kwargs: Additional arguments passed to `plotly.express.box()`.
638679
639680
Returns:
@@ -647,6 +688,7 @@ def box(
647688
facet_col=facet_col,
648689
facet_row=facet_row,
649690
animation_frame=animation_frame,
691+
colors=colors,
650692
**px_kwargs,
651693
)
652694

@@ -658,6 +700,7 @@ def pie(
658700
color: SlotValue = None,
659701
facet_col: SlotValue = auto,
660702
facet_row: SlotValue = auto,
703+
colors: Colors = None,
661704
**px_kwargs: Any,
662705
) -> go.Figure:
663706
"""Create an interactive pie chart.
@@ -668,6 +711,7 @@ def pie(
668711
color: Dimension for color grouping.
669712
facet_col: Dimension for subplot columns.
670713
facet_row: Dimension for subplot rows.
714+
colors: Color specification (scale name, list, or dict). See module docs.
671715
**px_kwargs: Additional arguments passed to `plotly.express.pie()`.
672716
673717
Returns:
@@ -680,5 +724,6 @@ def pie(
680724
color=color,
681725
facet_col=facet_col,
682726
facet_row=facet_row,
727+
colors=colors,
683728
**px_kwargs,
684729
)

0 commit comments

Comments
 (0)