Skip to content

Datashader support for points and shapes #244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
38beef7
prototype version with changed behavior regarding element order
Mar 19, 2024
9f01e91
add alpha & size control
Mar 20, 2024
32f0e20
simple color control
Mar 22, 2024
0685c35
update color handling
Mar 29, 2024
defb86b
first finished draft
Mar 30, 2024
3bfab39
add min_alpha to avoid undersaturation
Apr 2, 2024
bcecb0e
basic shapes datashader rendering
ckmah Apr 3, 2024
cc02f62
handle render shape colors; add parameter for render method
ckmah Apr 3, 2024
8e809f5
cleanup
ckmah Apr 3, 2024
c66e6cd
Merge pull request #243 from ckmah/feat/issue209_datashader_shapes
LucaMarconato Apr 3, 2024
9b39852
extent fixes, sum aggregation for coloring by numerical variable
May 1, 2024
5017c3c
Merge branch 'main' into feat/issue209_datashader
Sonja-Stockhaus Jun 20, 2024
31cee7d
post merge with main adaptations
Jun 20, 2024
0e44403
bugfixes
Jun 24, 2024
2bd4688
Merge branch 'main' into feat/issue209_datashader
Sonja-Stockhaus Jun 25, 2024
75f9a3d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 25, 2024
d1e2709
bugfix point transformation info lost
Jul 3, 2024
6a61693
render_shapes cleanup
Jul 9, 2024
e20811e
zorder bugfix and added tests for zorder and datashader stuff
Jul 9, 2024
a7aecb8
update test images
Jul 9, 2024
cf581b3
update test image
Jul 9, 2024
5cdc924
minor reformats
timtreis Jul 9, 2024
b244402
moved typecheck to correct function
timtreis Jul 9, 2024
8fce7dd
changelog and cleanup
Jul 10, 2024
f595c0d
transformation fix
Jul 10, 2024
7d0d481
comment update
Jul 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,24 @@ and this project adheres to [Semantic Versioning][].

## [0.2.3] - tbd

### Added

- Datashader support for points and shapes (#244)

### Changed

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

### Fixed

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

## [0.2.2] - 2024-05-02

### Fixed

- Fixed `fill_alpha` ignoring `alpha` channel from custom cmap
- Fixed `fill_alpha` ignoring `alpha` channel from custom cmap (#236)
- Fix channel str support (#221)

## [0.2.1] - 2024-03-26
Expand Down
25 changes: 23 additions & 2 deletions src/spatialdata_plot/pl/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def render_shapes(
cmap: Colormap | str | None = None,
norm: bool | Normalize = False,
scale: float | int = 1.0,
method: str | None = None,
table_name: str | None = None,
**kwargs: Any,
) -> sd.SpatialData:
Expand Down Expand Up @@ -219,6 +220,9 @@ def render_shapes(
Colormap normalization for continuous annotations.
scale : float | int, default 1.0
Value to scale circles, if present.
method : str | None, optional
Whether to use 'matplotlib' and 'datashader'. When None, the method is
chosen based on the size of the data.
table_name: str | None
Name of the table containing the color(s) columns. If one name is given than the table is used for each
spatial element to be plotted if the table annotates it. If you want to use different tables for particular
Expand Down Expand Up @@ -253,6 +257,7 @@ def render_shapes(
norm=norm,
scale=scale,
table_name=table_name,
method=method,
)

sdata = self._copy()
Expand Down Expand Up @@ -281,6 +286,8 @@ def render_shapes(
fill_alpha=param_values["fill_alpha"],
transfunc=kwargs.get("transfunc", None),
table_name=param_values["table_name"],
zorder=n_steps,
method=method,
)
n_steps += 1

Expand All @@ -298,6 +305,7 @@ def render_points(
cmap: Colormap | str | None = None,
norm: None | Normalize = None,
size: float | int = 1.0,
method: str | None = None,
table_name: str | None = None,
**kwargs: Any,
) -> sd.SpatialData:
Expand Down Expand Up @@ -342,6 +350,9 @@ def render_points(
Colormap normalization for continuous annotations.
size : float | int, default 1.0
Size of the points
method : str | None, optional
Whether to use 'matplotlib' and 'datashader'. When None, the method is
chosen based on the size of the data.
table_name: str | None
Name of the table containing the color(s) columns. If one name is given than the table is used for each
spatial element to be plotted if the table annotates it. If you want to use different tables for particular
Expand All @@ -368,6 +379,12 @@ def render_points(
table_name=table_name,
)

if method is not None:
if not isinstance(method, str):
raise TypeError("Parameter 'method' must be a string.")
if method not in ["matplotlib", "datashader"]:
raise ValueError("Parameter 'method' must be either 'matplotlib' or 'datashader'.")

sdata = self._copy()
sdata = _verify_plotting_tree(sdata)
n_steps = len(sdata.plotting_tree.keys())
Expand All @@ -391,6 +408,8 @@ def render_points(
transfunc=kwargs.get("transfunc", None),
size=param_values["size"],
table_name=param_values["table_name"],
zorder=n_steps,
method=method,
)
n_steps += 1

Expand Down Expand Up @@ -504,6 +523,7 @@ def render_images(
alpha=param_values["alpha"],
percentiles_for_norm=param_values["percentiles_for_norm"],
scale=param_values["scale"],
zorder=n_steps,
)
n_steps += 1

Expand All @@ -515,14 +535,14 @@ def render_labels(
element: str | None = None,
color: str | None = None,
groups: list[str] | str | None = None,
contour_px: int = 3,
contour_px: int | None = 3,
outline: bool = False,
palette: list[str] | str | None = None,
cmap: Colormap | str | None = None,
norm: Normalize | None = None,
na_color: ColorLike | None = (0.0, 0.0, 0.0, 0.0),
outline_alpha: float | int = 1.0,
fill_alpha: float | int = 0.3,
fill_alpha: float | int = 0.4,
scale: str | None = None,
table_name: str | None = None,
**kwargs: Any,
Expand Down Expand Up @@ -626,6 +646,7 @@ def render_labels(
transfunc=kwargs.get("transfunc", None),
scale=param_values["scale"],
table_name=param_values["table_name"],
zorder=n_steps,
)
n_steps += 1
return sdata
Expand Down
Loading
Loading