Skip to content

Commit bc2db2c

Browse files
Sonja-StockhausSonja StockhausLucaMarconatopre-commit-ci[bot]timtreis
authored
datashader speedup and bugfixes (#309)
Co-authored-by: Sonja Stockhaus <[email protected]> Co-authored-by: Luca Marconato <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Tim Treis <[email protected]>
1 parent 80c6f77 commit bc2db2c

29 files changed

+514
-105
lines changed

CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,22 @@ and this project adheres to [Semantic Versioning][].
88
[keep a changelog]: https://keepachangelog.com/en/1.0.0/
99
[semantic versioning]: https://semver.org/spec/v2.0.0.html
1010

11-
## [0.2.7] - 2024-09-04
11+
## [0.2.7] - tbd
1212

1313
### Added
1414

15-
-
15+
- The user can now specify `datashader_reduction` to control the rendering behaviour (#309)
16+
- Rendering outlines of shapes with datashader works now (#309)
1617

1718
### Changed
1819

1920
-
2021

2122
### Fixed
2223

24+
- datashader now uses canvas size = image size which speeds up the rendering (#309)
25+
- datashader now uses the `linear` as interpolation method for colormaps instead of the default `eq_hist` to make it equivalent to matplotlib (#309)
26+
- point sizes of datashader now agree with matplotlib also when dpi != 100 (#309)
2327
- Giving a custom colormap when rendering a multiscale image now works (#586)
2428

2529
## [0.2.6] - 2024-09-04

src/spatialdata_plot/pl/basic.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,15 @@ def render_shapes(
227227
Name of the table containing the color(s) columns. If one name is given than the table is used for each
228228
spatial element to be plotted if the table annotates it. If you want to use different tables for particular
229229
elements, as specified under element.
230+
230231
**kwargs : Any
231-
Additional arguments to be passed to cmap and norm.
232+
Additional arguments for customization. This can include:
233+
234+
datashader_reduction : Literal[
235+
"sum", "mean", "any", "count", "std", "var", "max", "min"
236+
], default: "sum"
237+
Reduction method for datashader when coloring by continuous values. Defaults to 'sum'.
238+
232239
233240
Notes
234241
-----
@@ -264,13 +271,13 @@ def render_shapes(
264271
scale=scale,
265272
table_name=table_name,
266273
method=method,
274+
ds_reduction=kwargs.get("datashader_reduction", None),
267275
)
268276

269277
sdata = self._copy()
270278
sdata = _verify_plotting_tree(sdata)
271279
n_steps = len(sdata.plotting_tree.keys())
272280
outline_params = _set_outline(outline_alpha > 0, outline_width, outline_color)
273-
274281
for element, param_values in params_dict.items():
275282
cmap_params = _prepare_cmap_norm(
276283
cmap=cmap,
@@ -291,7 +298,8 @@ def render_shapes(
291298
transfunc=kwargs.get("transfunc", None),
292299
table_name=param_values["table_name"],
293300
zorder=n_steps,
294-
method=method,
301+
method=param_values["method"],
302+
ds_reduction=param_values["ds_reduction"],
295303
)
296304
n_steps += 1
297305

@@ -361,8 +369,14 @@ def render_points(
361369
Name of the table containing the color(s) columns. If one name is given than the table is used for each
362370
spatial element to be plotted if the table annotates it. If you want to use different tables for particular
363371
elements, as specified under element.
364-
kwargs
365-
Additional arguments to be passed to cmap and norm.
372+
373+
**kwargs : Any
374+
Additional arguments for customization. This can include:
375+
376+
datashader_reduction : Literal[
377+
"sum", "mean", "any", "count", "std", "var", "max", "min"
378+
], default: "sum"
379+
Reduction method for datashader when coloring by continuous values. Defaults to 'sum'.
366380
367381
Returns
368382
-------
@@ -388,6 +402,7 @@ def render_points(
388402
norm=norm,
389403
size=size,
390404
table_name=table_name,
405+
ds_reduction=kwargs.get("datashader_reduction", None),
391406
)
392407

393408
if method is not None:
@@ -419,6 +434,7 @@ def render_points(
419434
table_name=param_values["table_name"],
420435
zorder=n_steps,
421436
method=method,
437+
ds_reduction=param_values["ds_reduction"],
422438
)
423439
n_steps += 1
424440

0 commit comments

Comments
 (0)