Skip to content

Commit 67a1699

Browse files
Merge pull request #244 from scverse/feat/issue209_datashader
Datashader support for points and shapes
2 parents ce64e4a + 7d0d481 commit 67a1699

15 files changed

+337
-71
lines changed

CHANGELOG.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,24 @@ and this project adheres to [Semantic Versioning][].
1212

1313
## [0.2.3] - 2024-07-03
1414

15+
### Added
16+
17+
- Datashader support for points and shapes (#244)
18+
1519
### Changed
1620

17-
- All parameters are now provided for a single element. If element in pl.render is None then this value will be broadcasted
21+
- All parameters are now provided for a single element (#272)
1822

1923
### Fixed
2024

2125
- Fix color assignment for NaN values (#257)
22-
- Fix channel str support #221
26+
- Zorder of rendering now strictly follows the order of the render_x calls (#244)
2327

2428
## [0.2.2] - 2024-05-02
2529

2630
### Fixed
2731

28-
- Fixed `fill_alpha` ignoring `alpha` channel from custom cmap
32+
- Fixed `fill_alpha` ignoring `alpha` channel from custom cmap (#236)
2933
- Fix channel str support (#221)
3034

3135
## [0.2.1] - 2024-03-26

src/spatialdata_plot/pl/basic.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ def render_shapes(
166166
cmap: Colormap | str | None = None,
167167
norm: bool | Normalize = False,
168168
scale: float | int = 1.0,
169+
method: str | None = None,
169170
table_name: str | None = None,
170171
**kwargs: Any,
171172
) -> sd.SpatialData:
@@ -219,6 +220,9 @@ def render_shapes(
219220
Colormap normalization for continuous annotations.
220221
scale : float | int, default 1.0
221222
Value to scale circles, if present.
223+
method : str | None, optional
224+
Whether to use 'matplotlib' and 'datashader'. When None, the method is
225+
chosen based on the size of the data.
222226
table_name: str | None
223227
Name of the table containing the color(s) columns. If one name is given than the table is used for each
224228
spatial element to be plotted if the table annotates it. If you want to use different tables for particular
@@ -253,6 +257,7 @@ def render_shapes(
253257
norm=norm,
254258
scale=scale,
255259
table_name=table_name,
260+
method=method,
256261
)
257262

258263
sdata = self._copy()
@@ -281,6 +286,8 @@ def render_shapes(
281286
fill_alpha=param_values["fill_alpha"],
282287
transfunc=kwargs.get("transfunc", None),
283288
table_name=param_values["table_name"],
289+
zorder=n_steps,
290+
method=method,
284291
)
285292
n_steps += 1
286293

@@ -298,6 +305,7 @@ def render_points(
298305
cmap: Colormap | str | None = None,
299306
norm: None | Normalize = None,
300307
size: float | int = 1.0,
308+
method: str | None = None,
301309
table_name: str | None = None,
302310
**kwargs: Any,
303311
) -> sd.SpatialData:
@@ -342,6 +350,9 @@ def render_points(
342350
Colormap normalization for continuous annotations.
343351
size : float | int, default 1.0
344352
Size of the points
353+
method : str | None, optional
354+
Whether to use 'matplotlib' and 'datashader'. When None, the method is
355+
chosen based on the size of the data.
345356
table_name: str | None
346357
Name of the table containing the color(s) columns. If one name is given than the table is used for each
347358
spatial element to be plotted if the table annotates it. If you want to use different tables for particular
@@ -368,6 +379,12 @@ def render_points(
368379
table_name=table_name,
369380
)
370381

382+
if method is not None:
383+
if not isinstance(method, str):
384+
raise TypeError("Parameter 'method' must be a string.")
385+
if method not in ["matplotlib", "datashader"]:
386+
raise ValueError("Parameter 'method' must be either 'matplotlib' or 'datashader'.")
387+
371388
sdata = self._copy()
372389
sdata = _verify_plotting_tree(sdata)
373390
n_steps = len(sdata.plotting_tree.keys())
@@ -391,6 +408,8 @@ def render_points(
391408
transfunc=kwargs.get("transfunc", None),
392409
size=param_values["size"],
393410
table_name=param_values["table_name"],
411+
zorder=n_steps,
412+
method=method,
394413
)
395414
n_steps += 1
396415

@@ -504,6 +523,7 @@ def render_images(
504523
alpha=param_values["alpha"],
505524
percentiles_for_norm=param_values["percentiles_for_norm"],
506525
scale=param_values["scale"],
526+
zorder=n_steps,
507527
)
508528
n_steps += 1
509529

@@ -515,14 +535,14 @@ def render_labels(
515535
element: str | None = None,
516536
color: str | None = None,
517537
groups: list[str] | str | None = None,
518-
contour_px: int = 3,
538+
contour_px: int | None = 3,
519539
outline: bool = False,
520540
palette: list[str] | str | None = None,
521541
cmap: Colormap | str | None = None,
522542
norm: Normalize | None = None,
523543
na_color: ColorLike | None = (0.0, 0.0, 0.0, 0.0),
524544
outline_alpha: float | int = 1.0,
525-
fill_alpha: float | int = 0.3,
545+
fill_alpha: float | int = 0.4,
526546
scale: str | None = None,
527547
table_name: str | None = None,
528548
**kwargs: Any,
@@ -626,6 +646,7 @@ def render_labels(
626646
transfunc=kwargs.get("transfunc", None),
627647
scale=param_values["scale"],
628648
table_name=param_values["table_name"],
649+
zorder=n_steps,
629650
)
630651
n_steps += 1
631652
return sdata

0 commit comments

Comments
 (0)