59
59
)
60
60
from spatialdata_plot .pp .utils import _verify_plotting_tree
61
61
62
+ # replace with
63
+ # from spatialdata._types import ColorLike
64
+ # once https://github.com/scverse/spatialdata/pull/689/ is in a release
62
65
ColorLike = Union [tuple [float , ...], str ]
63
66
64
67
@@ -158,11 +161,10 @@ def render_shapes(
158
161
fill_alpha : float | int = 1.0 ,
159
162
groups : list [str ] | str | None = None ,
160
163
palette : list [str ] | str | None = None ,
161
- na_color : ColorLike | None = "lightgrey" ,
162
- outline : bool = False ,
164
+ na_color : ColorLike | None = "default" ,
163
165
outline_width : float | int = 1.5 ,
164
166
outline_color : str | list [float ] = "#000000ff" ,
165
- outline_alpha : float | int = 1 .0 ,
167
+ outline_alpha : float | int = 0 .0 ,
166
168
cmap : Colormap | str | None = None ,
167
169
norm : bool | Normalize = False ,
168
170
scale : float | int = 1.0 ,
@@ -201,19 +203,17 @@ def render_shapes(
201
203
Palette for discrete annotations. List of valid color names that should be used for the categories. Must
202
204
match the number of groups. If element is None, broadcasting behaviour is attempted (use the same values for
203
205
all elements). If groups is provided but not palette, palette is set to default "lightgray".
204
- na_color : ColorLike | None, default "lightgrey"
206
+ na_color : ColorLike | None, default "default" (gets set to "lightgray")
205
207
Color to be used for NAs values, if present. Can either be a named color ("red"), a hex representation
206
208
("#000000ff") or a list of floats that represent RGB/RGBA values (1.0, 0.0, 0.0, 1.0). When None, the values
207
209
won't be shown.
208
- outline : bool, default False
209
- If `True`, a border around the shape elements is plotted.
210
210
outline_width : float | int, default 1.5
211
211
Width of the border.
212
212
outline_color : str | list[float], default "#000000ff"
213
213
Color of the border. Can either be a named color ("red"), a hex representation ("#000000ff") or a list of
214
214
floats that represent RGB/RGBA values (1.0, 0.0, 0.0, 1.0).
215
- outline_alpha : float | int, default 1 .0
216
- Alpha value for the outline of shapes.
215
+ outline_alpha : float | int, default 0 .0
216
+ Alpha value for the outline of shapes. Invisible by default.
217
217
cmap : Colormap | str | None, optional
218
218
Colormap for discrete or continuous annotations using 'color', see :class:`matplotlib.colors.Colormap`.
219
219
norm : bool | Normalize, default False
@@ -249,7 +249,6 @@ def render_shapes(
249
249
palette = palette ,
250
250
color = color ,
251
251
na_color = na_color ,
252
- outline = outline ,
253
252
outline_alpha = outline_alpha ,
254
253
outline_color = outline_color ,
255
254
outline_width = outline_width ,
@@ -263,16 +262,15 @@ def render_shapes(
263
262
sdata = self ._copy ()
264
263
sdata = _verify_plotting_tree (sdata )
265
264
n_steps = len (sdata .plotting_tree .keys ())
266
- cmap_params = _prepare_cmap_norm (
267
- cmap = cmap ,
268
- norm = norm ,
269
- na_color = na_color , # type: ignore[arg-type]
270
- ** kwargs ,
271
- )
272
-
273
- outline_params = _set_outline (outline , outline_width , outline_color )
265
+ outline_params = _set_outline (outline_alpha > 0 , outline_width , outline_color )
274
266
275
267
for element , param_values in params_dict .items ():
268
+ cmap_params = _prepare_cmap_norm (
269
+ cmap = cmap ,
270
+ norm = norm ,
271
+ na_color = params_dict [element ]["na_color" ], # type: ignore[arg-type]
272
+ ** kwargs ,
273
+ )
276
274
sdata .plotting_tree [f"{ n_steps + 1 } _render_shapes" ] = ShapesRenderParams (
277
275
element = element ,
278
276
color = param_values ["color" ],
@@ -301,7 +299,7 @@ def render_points(
301
299
alpha : float | int = 1.0 ,
302
300
groups : list [str ] | str | None = None ,
303
301
palette : list [str ] | str | None = None ,
304
- na_color : ColorLike | None = "lightgrey " ,
302
+ na_color : ColorLike | None = "default " ,
305
303
cmap : Colormap | str | None = None ,
306
304
norm : None | Normalize = None ,
307
305
size : float | int = 1.0 ,
@@ -339,7 +337,7 @@ def render_points(
339
337
Palette for discrete annotations. List of valid color names that should be used for the categories. Must
340
338
match the number of groups. If `element` is `None`, broadcasting behaviour is attempted (use the same values
341
339
for all elements). If groups is provided but not palette, palette is set to default "lightgray".
342
- na_color : ColorLike | None, default "lightgrey"
340
+ na_color : ColorLike | None, default "default" (gets set to "lightgray")
343
341
Color to be used for NAs values, if present. Can either be a named color ("red"), a hex representation
344
342
("#000000ff") or a list of floats that represent RGB/RGBA values (1.0, 0.0, 0.0, 1.0). When None, the values
345
343
won't be shown.
@@ -389,14 +387,13 @@ def render_points(
389
387
sdata = _verify_plotting_tree (sdata )
390
388
n_steps = len (sdata .plotting_tree .keys ())
391
389
392
- cmap_params = _prepare_cmap_norm (
393
- cmap = cmap ,
394
- norm = norm ,
395
- na_color = na_color , # type: ignore[arg-type]
396
- ** kwargs ,
397
- )
398
-
399
390
for element , param_values in params_dict .items ():
391
+ cmap_params = _prepare_cmap_norm (
392
+ cmap = cmap ,
393
+ norm = norm ,
394
+ na_color = param_values ["na_color" ], # type: ignore[arg-type]
395
+ ** kwargs ,
396
+ )
400
397
sdata .plotting_tree [f"{ n_steps + 1 } _render_points" ] = PointsRenderParams (
401
398
element = element ,
402
399
color = param_values ["color" ],
@@ -422,7 +419,7 @@ def render_images(
422
419
channel : list [str ] | list [int ] | str | int | None = None ,
423
420
cmap : list [Colormap | str ] | Colormap | str | None = None ,
424
421
norm : Normalize | None = None ,
425
- na_color : ColorLike | None = ( 0.0 , 0.0 , 0.0 , 0.0 ) ,
422
+ na_color : ColorLike | None = "default" ,
426
423
palette : list [str ] | str | None = None ,
427
424
alpha : float | int = 1.0 ,
428
425
percentiles_for_norm : tuple [float , float ] | None = None ,
@@ -452,8 +449,10 @@ def render_images(
452
449
norm : Normalize | None, optional
453
450
Colormap normalization for continuous annotations, see :class:`matplotlib.colors.Normalize`.
454
451
Applies to all channels if set.
455
- na_color : ColorLike | None, default (0.0, 0.0, 0.0, 0.0)
456
- Color to be used for NA values. Accepts color-like values (string, hex, RGB(A)).
452
+ na_color : ColorLike | None, default "default" (gets set to "lightgray")
453
+ Color to be used for NAs values, if present. Can either be a named color ("red"), a hex representation
454
+ ("#000000ff") or a list of floats that represent RGB/RGBA values (1.0, 0.0, 0.0, 1.0). When None, the values
455
+ won't be shown.
457
456
palette : list[str] | str | None
458
457
Palette to color images. The number of palettes should be equal to the number of channels.
459
458
alpha : float | int, default 1.0
@@ -494,27 +493,32 @@ def render_images(
494
493
sdata = _verify_plotting_tree (sdata )
495
494
n_steps = len (sdata .plotting_tree .keys ())
496
495
497
- cmap_params : list [CmapParams ] | CmapParams
498
- if isinstance (cmap , list ):
499
- cmap_params = [
500
- _prepare_cmap_norm (
501
- cmap = c ,
496
+ for element , param_values in params_dict .items ():
497
+ # cmap_params = _prepare_cmap_norm(
498
+ # cmap=params_dict[element]["cmap"],
499
+ # norm=norm,
500
+ # na_color=params_dict[element]["na_color"], # type: ignore[arg-type]
501
+ # **kwargs,
502
+ # )
503
+ cmap_params : list [CmapParams ] | CmapParams
504
+ if isinstance (cmap , list ):
505
+ cmap_params = [
506
+ _prepare_cmap_norm (
507
+ cmap = c ,
508
+ norm = norm ,
509
+ na_color = param_values ["na_color" ],
510
+ ** kwargs ,
511
+ )
512
+ for c in cmap
513
+ ]
514
+
515
+ else :
516
+ cmap_params = _prepare_cmap_norm (
517
+ cmap = cmap ,
502
518
norm = norm ,
503
- na_color = na_color , # type: ignore[arg-type]
519
+ na_color = param_values [ "na_color" ],
504
520
** kwargs ,
505
521
)
506
- for c in cmap
507
- ]
508
-
509
- else :
510
- cmap_params = _prepare_cmap_norm (
511
- cmap = cmap ,
512
- norm = norm ,
513
- na_color = na_color , # type: ignore[arg-type]
514
- ** kwargs ,
515
- )
516
-
517
- for element , param_values in params_dict .items ():
518
522
sdata .plotting_tree [f"{ n_steps + 1 } _render_images" ] = ImageRenderParams (
519
523
element = element ,
520
524
channel = param_values ["channel" ],
@@ -536,12 +540,11 @@ def render_labels(
536
540
color : str | None = None ,
537
541
groups : list [str ] | str | None = None ,
538
542
contour_px : int | None = 3 ,
539
- outline : bool = False ,
540
543
palette : list [str ] | str | None = None ,
541
544
cmap : Colormap | str | None = None ,
542
545
norm : Normalize | None = None ,
543
- na_color : ColorLike | None = ( 0.0 , 0.0 , 0.0 , 0.0 ) ,
544
- outline_alpha : float | int = 1 .0 ,
546
+ na_color : ColorLike | None = "default" ,
547
+ outline_alpha : float | int = 0 .0 ,
545
548
fill_alpha : float | int = 0.4 ,
546
549
scale : str | None = None ,
547
550
table_name : str | None = None ,
@@ -576,16 +579,16 @@ def render_labels(
576
579
contour_px : int, default 3
577
580
Draw contour of specified width for each segment. If `None`, fills entire segment, see:
578
581
func:`skimage.morphology.erosion`.
579
- outline : bool, default False
580
- Whether to plot boundaries around segmentation masks.
581
582
cmap : Colormap | str | None
582
583
Colormap for continuous annotations, see :class:`matplotlib.colors.Colormap`.
583
584
norm : Normalize | None
584
585
Colormap normalization for continuous annotations, see :class:`matplotlib.colors.Normalize`.
585
- na_color : ColorLike | None
586
- Color to be used for NAs values, if present.
587
- outline_alpha : float | int, default 1.0
588
- Alpha value for the outline of the labels.
586
+ na_color : ColorLike | None, default "default" (gets set to "lightgray")
587
+ Color to be used for NAs values, if present. Can either be a named color ("red"), a hex representation
588
+ ("#000000ff") or a list of floats that represent RGB/RGBA values (1.0, 0.0, 0.0, 1.0). When None, the values
589
+ won't be shown.
590
+ outline_alpha : float | int, default 0.0
591
+ Alpha value for the outline of the labels. Invisible by default.
589
592
fill_alpha : float | int, default 0.3
590
593
Alpha value for the fill of the labels.
591
594
scale : str | None
@@ -615,7 +618,6 @@ def render_labels(
615
618
groups = groups ,
616
619
na_color = na_color ,
617
620
norm = norm ,
618
- outline = outline ,
619
621
outline_alpha = outline_alpha ,
620
622
palette = palette ,
621
623
scale = scale ,
@@ -625,20 +627,19 @@ def render_labels(
625
627
sdata = self ._copy ()
626
628
sdata = _verify_plotting_tree (sdata )
627
629
n_steps = len (sdata .plotting_tree .keys ())
628
- cmap_params = _prepare_cmap_norm (
629
- cmap = cmap ,
630
- norm = norm ,
631
- na_color = na_color , # type: ignore[arg-type]
632
- ** kwargs ,
633
- )
634
630
635
631
for element , param_values in params_dict .items ():
632
+ cmap_params = _prepare_cmap_norm (
633
+ cmap = cmap ,
634
+ norm = norm ,
635
+ na_color = param_values ["na_color" ], # type: ignore[arg-type]
636
+ ** kwargs ,
637
+ )
636
638
sdata .plotting_tree [f"{ n_steps + 1 } _render_labels" ] = LabelsRenderParams (
637
639
element = element ,
638
640
color = param_values ["color" ],
639
641
groups = param_values ["groups" ],
640
642
contour_px = param_values ["contour_px" ],
641
- outline = param_values ["outline" ],
642
643
cmap_params = cmap_params ,
643
644
palette = param_values ["palette" ],
644
645
outline_alpha = param_values ["outline_alpha" ],
0 commit comments