@@ -139,7 +139,7 @@ def _copy(
139
139
140
140
def render_shapes (
141
141
self ,
142
- element : str | None = None ,
142
+ elements : str | list [ str ] | None = None ,
143
143
color : str | None = None ,
144
144
groups : str | Sequence [str ] | None = None ,
145
145
size : float = 1.0 ,
@@ -161,8 +161,8 @@ def render_shapes(
161
161
162
162
Parameters
163
163
----------
164
- element
165
- The name of the shapes element to render. If `None`, the first
164
+ elements
165
+ The name of the shapes element(s) to render. If `None`, all
166
166
shapes element in the `SpatialData` object will be used.
167
167
color
168
168
Key for annotations in :attr:`anndata.AnnData.obs` or variables/genes.
@@ -209,7 +209,7 @@ def render_shapes(
209
209
)
210
210
outline_params = _set_outline (size , outline , outline_width , outline_color )
211
211
sdata .plotting_tree [f"{ n_steps + 1 } _render_shapes" ] = ShapesRenderParams (
212
- element = element ,
212
+ elements = elements ,
213
213
color = color ,
214
214
groups = groups ,
215
215
outline_params = outline_params ,
@@ -219,13 +219,14 @@ def render_shapes(
219
219
palette = palette ,
220
220
outline_alpha = outline_alpha ,
221
221
fill_alpha = fill_alpha ,
222
+ transfunc = kwargs .get ("transfunc" , None ),
222
223
)
223
224
224
225
return sdata
225
226
226
227
def render_points (
227
228
self ,
228
- element : str | None = None ,
229
+ elements : str | list [ str ] | None = None ,
229
230
color : str | None = None ,
230
231
groups : str | Sequence [str ] | None = None ,
231
232
size : float = 1.0 ,
@@ -241,8 +242,8 @@ def render_points(
241
242
242
243
Parameters
243
244
----------
244
- element
245
- The name of the points element to render. If `None`, the first
245
+ elements
246
+ The name of the points element(s) to render. If `None`, all
246
247
shapes element in the `SpatialData` object will be used.
247
248
color
248
249
Key for annotations in :attr:`anndata.AnnData.obs` or variables/genes.
@@ -278,19 +279,21 @@ def render_points(
278
279
** kwargs ,
279
280
)
280
281
sdata .plotting_tree [f"{ n_steps + 1 } _render_points" ] = PointsRenderParams (
281
- element = element ,
282
+ elements = elements ,
282
283
color = color ,
283
284
groups = groups ,
284
285
cmap_params = cmap_params ,
285
286
palette = palette ,
286
287
alpha = alpha ,
288
+ transfunc = kwargs .get ("transfunc" , None ),
289
+ size = size ,
287
290
)
288
291
289
292
return sdata
290
293
291
294
def render_images (
292
295
self ,
293
- element : str | None = None ,
296
+ elements : str | list [ str ] | None = None ,
294
297
channel : list [str ] | list [int ] | int | str | None = None ,
295
298
cmap : Colormap | str | None = None ,
296
299
norm : Optional [Normalize ] = None ,
@@ -304,9 +307,9 @@ def render_images(
304
307
305
308
Parameters
306
309
----------
307
- element
308
- The name of the image element to render. If `None`, the first
309
- shapes element in the `SpatialData` object will be used.
310
+ elements
311
+ The name of the image element(s) to render. If `None`, all
312
+ shapes elements in the `SpatialData` object will be used.
310
313
channel
311
314
To select which channel to plot (all by default).
312
315
cmap
@@ -335,7 +338,7 @@ def render_images(
335
338
** kwargs ,
336
339
)
337
340
sdata .plotting_tree [f"{ n_steps + 1 } _render_images" ] = ImageRenderParams (
338
- element = element ,
341
+ elements = elements ,
339
342
channel = channel ,
340
343
cmap_params = cmap_params ,
341
344
palette = palette ,
@@ -346,7 +349,7 @@ def render_images(
346
349
347
350
def render_labels (
348
351
self ,
349
- element : str | None = None ,
352
+ elements : str | list [ str ] | None = None ,
350
353
color : str | None = None ,
351
354
groups : str | Sequence [str ] | None = None ,
352
355
contour_px : int = 3 ,
@@ -366,9 +369,9 @@ def render_labels(
366
369
367
370
Parameters
368
371
----------
369
- element
370
- The name of the labels element to render. If `None`, the first
371
- labels element in the `SpatialData` object will be used.
372
+ elements
373
+ The name of the labels element(s) to render. If `None`, all
374
+ labels elements in the `SpatialData` object will be used.
372
375
color
373
376
Key for annotations in :attr:`anndata.AnnData.obs` or variables/genes.
374
377
groups
@@ -417,7 +420,7 @@ def render_labels(
417
420
** kwargs ,
418
421
)
419
422
sdata .plotting_tree [f"{ n_steps + 1 } _render_labels" ] = LabelsRenderParams (
420
- element = element ,
423
+ elements = elements ,
421
424
color = color ,
422
425
groups = groups ,
423
426
contour_px = contour_px ,
@@ -428,6 +431,7 @@ def render_labels(
428
431
palette = palette ,
429
432
outline_alpha = outline_alpha ,
430
433
fill_alpha = fill_alpha ,
434
+ transfunc = kwargs .get ("transfunc" , None ),
431
435
)
432
436
433
437
return sdata
@@ -519,6 +523,15 @@ def show(
519
523
# Simplicstic solution: If the images are multiscale, just use the first
520
524
sdata = _multiscale_to_image (sdata )
521
525
526
+ # handle coordinate system
527
+ coordinate_systems = sdata .coordinate_systems if coordinate_systems is None else coordinate_systems
528
+ if isinstance (coordinate_systems , str ):
529
+ coordinate_systems = [coordinate_systems ]
530
+
531
+ for cs in coordinate_systems :
532
+ if cs not in sdata .coordinate_systems :
533
+ raise ValueError (f"Unknown coordinate system '{ cs } ', valid choices are: { sdata .coordinate_systems } " )
534
+
522
535
extent = _get_extent (
523
536
sdata = sdata ,
524
537
has_images = "render_images" in render_cmds ,
@@ -528,11 +541,6 @@ def show(
528
541
coordinate_systems = coordinate_systems ,
529
542
)
530
543
531
- # handle coordinate system
532
- coordinate_systems = sdata .coordinate_systems if coordinate_systems is None else coordinate_systems
533
- if isinstance (coordinate_systems , str ):
534
- coordinate_systems = [coordinate_systems ]
535
-
536
544
# Use extent to filter out coordinate system without the relevant elements
537
545
valid_cs = []
538
546
for cs in coordinate_systems :
@@ -542,13 +550,18 @@ def show(
542
550
logg .info (f"Dropping coordinate system '{ cs } ' since it doesn't have relevant elements." )
543
551
coordinate_systems = valid_cs
544
552
553
+ # print(coordinate_systems)
554
+ # cs_mapping = _get_coordinate_system_mapping(sdata)
555
+ # print(cs_mapping)
556
+
545
557
# check that coordinate system and elements to be rendered match
546
- for cmd , params in render_cmds .items ():
547
- if params .element is not None and len ([params .element ]) != len (coordinate_systems ):
548
- raise ValueError (
549
- f"Number of coordinate systems ({ len (coordinate_systems )} ) does not match number of elements "
550
- f"({ len (params .element )} ) in command { cmd } ."
551
- )
558
+ # for cmd, params in render_cmds.items():
559
+ # if params.elements is not None and len([params.elements]) != len(coordinate_systems):
560
+ # print(params.elements)
561
+ # raise ValueError(
562
+ # f"Number of coordinate systems ({len(coordinate_systems)}) does not match number of elements "
563
+ # f"({len(params.elements)}) in command {cmd}."
564
+ # )
552
565
553
566
# set up canvas
554
567
fig_params , scalebar_params = _prepare_params_plot (
@@ -679,8 +692,15 @@ def show(
679
692
cs_contents .query (f"cs == '{ cs } '" )["has_shapes" ][0 ],
680
693
]
681
694
):
682
- ax .set_xlim (extent [cs ][0 ], extent [cs ][1 ])
683
- ax .set_ylim (extent [cs ][3 ], extent [cs ][2 ]) # (0, 0) is top-left
695
+ # If the axis already has limits, only expand them but not overwrite
696
+ x_min , x_max = ax .get_xlim ()
697
+ y_min , y_max = ax .get_ylim ()
698
+ x_min = min (x_min , extent [cs ][0 ])
699
+ x_max = max (x_max , extent [cs ][1 ])
700
+ y_min = min (y_min , extent [cs ][2 ])
701
+ y_max = max (y_max , extent [cs ][3 ])
702
+ ax .set_xlim (x_min , x_max )
703
+ ax .set_ylim (y_max , y_min ) # (0, 0) is top-left
684
704
685
705
if fig_params .fig is not None and save is not None :
686
706
save_fig (fig_params .fig , path = save )
0 commit comments