Skip to content

Commit 16d057e

Browse files
added tests for plotting columns from points (#395)
2 parents 62e8b5a + 6ab64b8 commit 16d057e

7 files changed

+82
-63
lines changed

CHANGELOG.md

Lines changed: 64 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -12,167 +12,169 @@ and this project adheres to [Semantic Versioning][].
1212

1313
### Fixed
1414

15-
- Transformations of Points and Shapes are now applied before rendering with datashader (#378)
16-
- Fix bug due to `sc.get.obs_df()` returning a different type (#393)
15+
- Transformations of Points and Shapes are now applied before rendering with datashader (#378)
16+
- Fix bug due to `sc.get.obs_df()` returning a different type (#393)
17+
- Allowing instance mismatch between shapes and tables (#396)
18+
- Fix bug when plotting categorical points with datashader (#395)
1719

1820
## [0.2.8] - 2024-11-26
1921

2022
### Changed
2123

22-
- Support for `xarray.DataTree` (which moved from `datatree.DataTree`) (#380)
24+
- Support for `xarray.DataTree` (which moved from `datatree.DataTree`) (#380)
2325

2426
## [0.2.7] - 2024-10-24
2527

2628
### Added
2729

28-
- The user can now specify `datashader_reduction` to control the rendering behaviour (#309)
29-
- Rendering outlines of shapes with datashader works now (#309)
30+
- The user can now specify `datashader_reduction` to control the rendering behavior (#309)
31+
- Rendering outlines of shapes with datashader works now (#309)
3032

3133
### Fixed
3234

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

3840
## [0.2.6] - 2024-09-04
3941

4042
### Changed
4143

42-
- Lowered RMSE-threshold for plot-based tests from 45 to 15 (#344)
43-
- When subsetting to `groups`, `NA` isn't automatically added to legend (#344)
44-
- When rendering a single image channel, a colorbar is now shown (#346)
45-
- Removed `percentiles_for_norm` parameter (#346)
46-
- Changed `norm` to no longer accept bools, only `mpl.colors.Normalise` or `None` (#346)
44+
- Lowered RMSE-threshold for plot-based tests from 45 to 15 (#344)
45+
- When subsetting to `groups`, `NA` isn't automatically added to legend (#344)
46+
- When rendering a single image channel, a colorbar is now shown (#346)
47+
- Removed `percentiles_for_norm` parameter (#346)
48+
- Changed `norm` to no longer accept bools, only `mpl.colors.Normalise` or `None` (#346)
4749

4850
### Fixed
4951

50-
- Filtering with `groups` now preserves original cmap (#344)
51-
- Non-selected `groups` are now not shown in `na_color` (#344)
52-
- Several issues associated with `norm` and `colorbar` (#346)
52+
- Filtering with `groups` now preserves original cmap (#344)
53+
- Non-selected `groups` are now not shown in `na_color` (#344)
54+
- Several issues associated with `norm` and `colorbar` (#346)
5355

5456
## [0.2.5] - 2024-08-23
5557

5658
### Changed
5759

58-
- Replaced `outline` parameter in `render_labels` with alpha-based logic (#323)
59-
- Lowered RMSE-threshold for plot-based tests from 60 to 45 (#323)
60-
- Removed `preprocessing` (.pp) accessor (#329)
60+
- Replaced `outline` parameter in `render_labels` with alpha-based logic (#323)
61+
- Lowered RMSE-threshold for plot-based tests from 60 to 45 (#323)
62+
- Removed `preprocessing` (.pp) accessor (#329)
6163

6264
### Fixed
6365

64-
- Minor fixes for several tests as a result of the threshold change (#323)
66+
- Minor fixes for several tests as a result of the threshold change (#323)
6567

6668
## [0.2.4] - 2024-08-07
6769

6870
### Added
6971

70-
- Added utils function for 0-transparent cmaps (#302)
72+
- Added utils function for 0-transparent cmaps (#302)
7173

7274
### Fixed
7375

74-
- Took RNG out of categorical label test (#306)
75-
- Performance bug when plotting shapes (#298)
76-
- scale parameter was ignored for single-scale images (#301)
77-
- Changes to support for dask-expr (#283)
78-
- Added error handling for non-existent elements (#305)
79-
- Specifying vmin and vmax properly clips image data (#307)
80-
- import bug `get_cmap()` (8fd969c)
76+
- Took RNG out of categorical label test (#306)
77+
- Performance bug when plotting shapes (#298)
78+
- scale parameter was ignored for single-scale images (#301)
79+
- Changes to support for dask-expr (#283)
80+
- Added error handling for non-existent elements (#305)
81+
- Specifying vmin and vmax properly clips image data (#307)
82+
- import bug `get_cmap()` (8fd969c)
8183

8284
## [0.2.3] - 2024-07-03
8385

8486
### Added
8587

86-
- Datashader support for points and shapes (#244)
88+
- Datashader support for points and shapes (#244)
8789

8890
### Changed
8991

90-
- All parameters are now provided for a single element (#272)
92+
- All parameters are now provided for a single element (#272)
9193

9294
### Fixed
9395

94-
- Fix color assignment for NaN values (#257)
95-
- Zorder of rendering now strictly follows the order of the render_x calls (#244)
96+
- Fix color assignment for NaN values (#257)
97+
- Zorder of rendering now strictly follows the order of the render_x calls (#244)
9698

9799
## [0.2.2] - 2024-05-02
98100

99101
### Fixed
100102

101-
- Fixed `fill_alpha` ignoring `alpha` channel from custom cmap (#236)
102-
- Fix channel str support (#221)
103+
- Fixed `fill_alpha` ignoring `alpha` channel from custom cmap (#236)
104+
- Fix channel str support (#221)
103105

104106
## [0.2.1] - 2024-03-26
105107

106108
### Minor
107109

108-
- Adjusted GitHub worklows
110+
- Adjusted GitHub worklows
109111

110112
## [0.2.0] - 2024-03-24
111113

112114
### Added
113115

114-
- Support for plotting multiple tables @melonora
116+
- Support for plotting multiple tables @melonora
115117

116118
### Fixed
117119

118-
- Several bugfixes, especially for colors and palettes @melonora
120+
- Several bugfixes, especially for colors and palettes @melonora
119121

120122
## [0.1.0] - 2024-01-17
121123

122124
### Added
123125

124-
- Multiscale image handling: user can specify a scale, else the best scale is selected automatically given the figure size and dpi (#164)
125-
- Large images are automatically rasterized to speed up performance (#164)
126-
- Added better error message for mismatch in cs and ax number (#185)
127-
- Beter test coverage for correct plotting of elements after transformation (#198)
128-
- Can now stack render commands (#190, #192)
129-
- The `color` argument in render_shapes/points now accepts actual colors as well (#199)
130-
- Input arguments are now evaulated for their types in basic.py (#199)
126+
- Multiscale image handling: user can specify a scale, else the best scale is selected automatically given the figure size and dpi (#164)
127+
- Large images are automatically rasterized to speed up performance (#164)
128+
- Added better error message for mismatch in cs and ax number (#185)
129+
- Beter test coverage for correct plotting of elements after transformation (#198)
130+
- Can now stack render commands (#190, #192)
131+
- The `color` argument in render_shapes/points now accepts actual colors as well (#199)
132+
- Input arguments are now evaulated for their types in basic.py (#199)
131133

132134
### Fixed
133135

134-
- Now dropping index when plotting shapes after spatial query (#177)
135-
- Points are now being correctly rotated (#198)
136-
- User can now pass Colormap objects to the cmap argument in render_images. When only one cmap is given for 3 channels, it is now applied to each channel (#188, #194)
136+
- Now dropping index when plotting shapes after spatial query (#177)
137+
- Points are now being correctly rotated (#198)
138+
- User can now pass Colormap objects to the cmap argument in render_images. When only one cmap is given for 3 channels, it is now applied to each channel (#188, #194)
137139

138140
## [0.0.6] - 2023-11-06
139141

140142
### Added
141143

142-
- Pushed `get_extent` functionality upstream to `spatialdata` (#162)
144+
- Pushed `get_extent` functionality upstream to `spatialdata` (#162)
143145

144146
## [0.0.5] - 2023-10-02
145147

146148
### Added
147149

148-
- Can now scale shapes (#152)
149-
- Can now plot columns from GeoDataFrame (#149)
150+
- Can now scale shapes (#152)
151+
- Can now plot columns from GeoDataFrame (#149)
150152

151153
### Fixed
152154

153-
- Multipolygons are now handled correctly (#93)
154-
- Legend order is now deterministic (#143)
155-
- Images no longer normalised by default (#150)
156-
- Filtering of shapes and points using the `groups` argument is now possible, coloring by palette and cmap arguments works for shapes and points (#153)
157-
- Colorbar no longer autoscales to [0, 1] (#155)
158-
- Plotting shapes after a spatial query is now possible (#163)
155+
- Multipolygons are now handled correctly (#93)
156+
- Legend order is now deterministic (#143)
157+
- Images no longer normalised by default (#150)
158+
- Filtering of shapes and points using the `groups` argument is now possible, coloring by palette and cmap arguments works for shapes and points (#153)
159+
- Colorbar no longer autoscales to [0, 1] (#155)
160+
- Plotting shapes after a spatial query is now possible (#163)
159161

160162
## [0.0.4] - 2023-08-11
161163

162164
### Fixed
163165

164-
- Multi-scale images/labels are now correctly substituted and the action is logged (#131).
165-
- Empty geometries among the shapes can be handeled (#133).
166-
- `outline_width` parameter in render_shapes is now a float that actually determines the line width (#139).
166+
- Multi-scale images/labels are now correctly substituted and the action is logged (#131).
167+
- Empty geometries among the shapes can be handeled (#133).
168+
- `outline_width` parameter in render_shapes is now a float that actually determines the line width (#139).
167169

168170
## [0.0.2] - 2023-06-25
169171

170172
### Fixed
171173

172-
- Multiple bugfixes of which I didn't keep track of.
174+
- Multiple bugfixes of which I didn't keep track of.
173175

174176
## [0.0.1] - 2023-04-04
175177

176178
### Added
177179

178-
- Initial release of `spatialdata-plot` with support for `images`, `labels`, `points` and `shapes`.
180+
- Initial release of `spatialdata-plot` with support for `images`, `labels`, `points` and `shapes`.

src/spatialdata_plot/pl/render.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,12 @@ def _render_points(
525525
# use datashader for the visualization of points
526526
cvs = ds.Canvas(plot_width=plot_width, plot_height=plot_height, x_range=x_ext, y_range=y_ext)
527527

528-
color_by_categorical = col_for_color is not None and points[col_for_color].values.dtype == object
528+
color_by_categorical = col_for_color is not None and transformed_element[col_for_color].values.dtype in (
529+
object,
530+
"categorical",
531+
)
532+
if color_by_categorical and transformed_element[col_for_color].values.dtype == object:
533+
transformed_element[col_for_color] = transformed_element[col_for_color].astype("category")
529534
aggregate_with_reduction = None
530535
if col_for_color is not None and (render_params.groups is None or len(render_params.groups) > 1):
531536
if color_by_categorical:
Loading
Loading
Loading
Loading

tests/pl/test_render_points.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,18 @@ def test_plot_datashader_continuous_color(self, sdata_blobs: SpatialData):
111111
element="blobs_points", size=40, color="instance_id", alpha=0.6, method="datashader"
112112
).pl.show()
113113

114+
def test_plot_points_categorical_color_column_matplotlib(self, sdata_blobs: SpatialData):
115+
sdata_blobs.pl.render_points("blobs_points", color="genes", method="matplotlib").pl.show()
116+
117+
def test_plot_points_categorical_color_column_datashader(self, sdata_blobs: SpatialData):
118+
sdata_blobs.pl.render_points("blobs_points", color="genes", method="datashader").pl.show()
119+
120+
def test_plot_points_continuous_color_column_matplotlib(self, sdata_blobs: SpatialData):
121+
sdata_blobs.pl.render_points("blobs_points", color="instance_id", method="matplotlib").pl.show()
122+
123+
def test_plot_points_continuous_color_column_datashader(self, sdata_blobs: SpatialData):
124+
sdata_blobs.pl.render_points("blobs_points", color="instance_id", method="datashader").pl.show()
125+
114126
def test_plot_datashader_matplotlib_stack(self, sdata_blobs: SpatialData):
115127
sdata_blobs.pl.render_points(
116128
element="blobs_points", size=40, color="red", method="datashader"

0 commit comments

Comments
 (0)