From e1a0e2cbe1bd90f713eed54d6d28398083c3115a Mon Sep 17 00:00:00 2001 From: Luca Marconato Date: Tue, 17 Dec 2024 17:50:44 +0100 Subject: [PATCH 1/8] fix isinstance --- src/spatialdata_plot/pl/basic.py | 2 +- src/spatialdata_plot/pl/render.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/spatialdata_plot/pl/basic.py b/src/spatialdata_plot/pl/basic.py index 78c59436..d23b9710 100644 --- a/src/spatialdata_plot/pl/basic.py +++ b/src/spatialdata_plot/pl/basic.py @@ -949,7 +949,7 @@ def show( if wanted_labels_on_this_cs: if (table := params_copy.table_name) is not None: colors = sc.get.obs_df(sdata[table], params_copy.color) - if isinstance(colors[params_copy.color].dtype, pd.CategoricalDtype): + if isinstance(colors.dtype, pd.CategoricalDtype): _maybe_set_colors( source=sdata[table], target=sdata[table], diff --git a/src/spatialdata_plot/pl/render.py b/src/spatialdata_plot/pl/render.py index a3a6c1a1..a8a07058 100644 --- a/src/spatialdata_plot/pl/render.py +++ b/src/spatialdata_plot/pl/render.py @@ -441,7 +441,7 @@ def _render_points( if col_for_color is not None: cols = sc.get.obs_df(adata, col_for_color) # maybe set color based on type - if isinstance(cols[col_for_color].dtype, pd.CategoricalDtype): + if isinstance(cols.dtype, pd.CategoricalDtype): _maybe_set_colors( source=adata, target=adata, From 8d8d2736fd146ca8318da03d3f50f7bc8338ad03 Mon Sep 17 00:00:00 2001 From: Luca Marconato Date: Tue, 17 Dec 2024 17:56:03 +0100 Subject: [PATCH 2/8] update changelog --- CHANGELOG.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4003fe9b..dc20d2da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,9 +8,15 @@ and this project adheres to [Semantic Versioning][]. [keep a changelog]: https://keepachangelog.com/en/1.0.0/ [semantic versioning]: https://semver.org/spec/v2.0.0.html +## incoming version + +### Fixed + +- Fix bug due to `sc.get.obs_df()` returning a different type (#393) + ## [0.2.8] - 2024-11-26 -- Support for `xarray.DataTree` (which moved from `datatree.DataTree`) +- Support for `xarray.DataTree` (which moved from `datatree.DataTree`) ## [0.2.7] - 2024-10-24 From f28345dbd89faacb2e686538a46f65e4f0482936 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 17 Dec 2024 16:57:20 +0000 Subject: [PATCH 3/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- CHANGELOG.md | 124 +++++++++++++++++++++---------------------- README.md | 4 +- docs/contributing.md | 18 +++---- 3 files changed, 73 insertions(+), 73 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b47acbf..9a866e14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,167 +12,167 @@ and this project adheres to [Semantic Versioning][]. ### Fixed -- Transformations of Points and Shapes are now applied before rendering with datashader (#378) -- Fix bug due to `sc.get.obs_df()` returning a different type (#393) +- Transformations of Points and Shapes are now applied before rendering with datashader (#378) +- Fix bug due to `sc.get.obs_df()` returning a different type (#393) ## [0.2.8] - 2024-11-26 ### Changed -- Support for `xarray.DataTree` (which moved from `datatree.DataTree`) (#380) +- Support for `xarray.DataTree` (which moved from `datatree.DataTree`) (#380) ## [0.2.7] - 2024-10-24 ### Added -- The user can now specify `datashader_reduction` to control the rendering behaviour (#309) -- Rendering outlines of shapes with datashader works now (#309) +- The user can now specify `datashader_reduction` to control the rendering behaviour (#309) +- Rendering outlines of shapes with datashader works now (#309) ### Fixed -- datashader now uses canvas size = image size which speeds up the rendering (#309) -- datashader now uses the `linear` as interpolation method for colormaps instead of the default `eq_hist` to make it equivalent to matplotlib (#309) -- point sizes of datashader now agree with matplotlib also when dpi != 100 (#309) -- Giving a custom colormap when rendering a multiscale image now works (#586) +- datashader now uses canvas size = image size which speeds up the rendering (#309) +- datashader now uses the `linear` as interpolation method for colormaps instead of the default `eq_hist` to make it equivalent to matplotlib (#309) +- point sizes of datashader now agree with matplotlib also when dpi != 100 (#309) +- Giving a custom colormap when rendering a multiscale image now works (#586) ## [0.2.6] - 2024-09-04 ### Changed -- Lowered RMSE-threshold for plot-based tests from 45 to 15 (#344) -- When subsetting to `groups`, `NA` isn't automatically added to legend (#344) -- When rendering a single image channel, a colorbar is now shown (#346) -- Removed `percentiles_for_norm` parameter (#346) -- Changed `norm` to no longer accept bools, only `mpl.colors.Normalise` or `None` (#346) +- Lowered RMSE-threshold for plot-based tests from 45 to 15 (#344) +- When subsetting to `groups`, `NA` isn't automatically added to legend (#344) +- When rendering a single image channel, a colorbar is now shown (#346) +- Removed `percentiles_for_norm` parameter (#346) +- Changed `norm` to no longer accept bools, only `mpl.colors.Normalise` or `None` (#346) ### Fixed -- Filtering with `groups` now preserves original cmap (#344) -- Non-selected `groups` are now not shown in `na_color` (#344) -- Several issues associated with `norm` and `colorbar` (#346) +- Filtering with `groups` now preserves original cmap (#344) +- Non-selected `groups` are now not shown in `na_color` (#344) +- Several issues associated with `norm` and `colorbar` (#346) ## [0.2.5] - 2024-08-23 ### Changed -- Replaced `outline` parameter in `render_labels` with alpha-based logic (#323) -- Lowered RMSE-threshold for plot-based tests from 60 to 45 (#323) -- Removed `preprocessing` (.pp) accessor (#329) +- Replaced `outline` parameter in `render_labels` with alpha-based logic (#323) +- Lowered RMSE-threshold for plot-based tests from 60 to 45 (#323) +- Removed `preprocessing` (.pp) accessor (#329) ### Fixed -- Minor fixes for several tests as a result of the threshold change (#323) +- Minor fixes for several tests as a result of the threshold change (#323) ## [0.2.4] - 2024-08-07 ### Added -- Added utils function for 0-transparent cmaps (#302) +- Added utils function for 0-transparent cmaps (#302) ### Fixed -- Took RNG out of categorical label test (#306) -- Performance bug when plotting shapes (#298) -- scale parameter was ignored for single-scale images (#301) -- Changes to support for dask-expr (#283) -- Added error handling for non-existent elements (#305) -- Specifying vmin and vmax properly clips image data (#307) -- import bug `get_cmap()` (8fd969c) +- Took RNG out of categorical label test (#306) +- Performance bug when plotting shapes (#298) +- scale parameter was ignored for single-scale images (#301) +- Changes to support for dask-expr (#283) +- Added error handling for non-existent elements (#305) +- Specifying vmin and vmax properly clips image data (#307) +- import bug `get_cmap()` (8fd969c) ## [0.2.3] - 2024-07-03 ### Added -- Datashader support for points and shapes (#244) +- Datashader support for points and shapes (#244) ### Changed -- All parameters are now provided for a single element (#272) +- All parameters are now provided for a single element (#272) ### Fixed -- Fix color assignment for NaN values (#257) -- Zorder of rendering now strictly follows the order of the render_x calls (#244) +- Fix color assignment for NaN values (#257) +- 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 (#236) -- Fix channel str support (#221) +- Fixed `fill_alpha` ignoring `alpha` channel from custom cmap (#236) +- Fix channel str support (#221) ## [0.2.1] - 2024-03-26 ### Minor -- Adjusted GitHub worklows +- Adjusted GitHub worklows ## [0.2.0] - 2024-03-24 ### Added -- Support for plotting multiple tables @melonora +- Support for plotting multiple tables @melonora ### Fixed -- Several bugfixes, especially for colors and palettes @melonora +- Several bugfixes, especially for colors and palettes @melonora ## [0.1.0] - 2024-01-17 ### Added -- Multiscale image handling: user can specify a scale, else the best scale is selected automatically given the figure size and dpi (#164) -- Large images are automatically rasterized to speed up performance (#164) -- Added better error message for mismatch in cs and ax number (#185) -- Beter test coverage for correct plotting of elements after transformation (#198) -- Can now stack render commands (#190, #192) -- The `color` argument in render_shapes/points now accepts actual colors as well (#199) -- Input arguments are now evaulated for their types in basic.py (#199) +- Multiscale image handling: user can specify a scale, else the best scale is selected automatically given the figure size and dpi (#164) +- Large images are automatically rasterized to speed up performance (#164) +- Added better error message for mismatch in cs and ax number (#185) +- Beter test coverage for correct plotting of elements after transformation (#198) +- Can now stack render commands (#190, #192) +- The `color` argument in render_shapes/points now accepts actual colors as well (#199) +- Input arguments are now evaulated for their types in basic.py (#199) ### Fixed -- Now dropping index when plotting shapes after spatial query (#177) -- Points are now being correctly rotated (#198) -- 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) +- Now dropping index when plotting shapes after spatial query (#177) +- Points are now being correctly rotated (#198) +- 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) ## [0.0.6] - 2023-11-06 ### Added -- Pushed `get_extent` functionality upstream to `spatialdata` (#162) +- Pushed `get_extent` functionality upstream to `spatialdata` (#162) ## [0.0.5] - 2023-10-02 ### Added -- Can now scale shapes (#152) -- Can now plot columns from GeoDataFrame (#149) +- Can now scale shapes (#152) +- Can now plot columns from GeoDataFrame (#149) ### Fixed -- Multipolygons are now handled correctly (#93) -- Legend order is now deterministic (#143) -- Images no longer normalised by default (#150) -- Filtering of shapes and points using the `groups` argument is now possible, coloring by palette and cmap arguments works for shapes and points (#153) -- Colorbar no longer autoscales to [0, 1] (#155) -- Plotting shapes after a spatial query is now possible (#163) +- Multipolygons are now handled correctly (#93) +- Legend order is now deterministic (#143) +- Images no longer normalised by default (#150) +- Filtering of shapes and points using the `groups` argument is now possible, coloring by palette and cmap arguments works for shapes and points (#153) +- Colorbar no longer autoscales to [0, 1] (#155) +- Plotting shapes after a spatial query is now possible (#163) ## [0.0.4] - 2023-08-11 ### Fixed -- Multi-scale images/labels are now correctly substituted and the action is logged (#131). -- Empty geometries among the shapes can be handeled (#133). -- `outline_width` parameter in render_shapes is now a float that actually determines the line width (#139). +- Multi-scale images/labels are now correctly substituted and the action is logged (#131). +- Empty geometries among the shapes can be handeled (#133). +- `outline_width` parameter in render_shapes is now a float that actually determines the line width (#139). ## [0.0.2] - 2023-06-25 ### Fixed -- Multiple bugfixes of which I didn't keep track of. +- Multiple bugfixes of which I didn't keep track of. ## [0.0.1] - 2023-04-04 ### Added -- Initial release of `spatialdata-plot` with support for `images`, `labels`, `points` and `shapes`. +- Initial release of `spatialdata-plot` with support for `images`, `labels`, `points` and `shapes`. diff --git a/README.md b/README.md index 5dc823a5..ba786da3 100644 --- a/README.md +++ b/README.md @@ -26,8 +26,8 @@ SpatialData’s plotting capabilities allow to quickly visualise all contained m For more information on the `spatialdata-plot` library, please refer to the [documentation](https://spatialdata.scverse.org/projects/plot/en/latest/index.html). In particular, the -- [API documentation][link-api]. -- [Example notebooks][link-notebooks] (section "Visiualizations") +- [API documentation][link-api]. +- [Example notebooks][link-notebooks] (section "Visiualizations") ## Installation diff --git a/docs/contributing.md b/docs/contributing.md index 66a84688..77e97aae 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -99,11 +99,11 @@ Specify `vX.X.X` as a tag name and create a release. For more information, see [ Please write documentation for new or changed features and use-cases. This project uses [sphinx][] with the following features: -- the [myst][] extension allows to write documentation in markdown/Markedly Structured Text -- [Numpy-style docstrings][numpydoc] (through the [napoloen][numpydoc-napoleon] extension). -- Jupyter notebooks as tutorials through [myst-nb][] (See [Tutorials with myst-nb](#tutorials-with-myst-nb-and-jupyter-notebooks)) -- [Sphinx autodoc typehints][], to automatically reference annotated input and output types -- Citations (like {cite:p}`Virshup_2023`) can be included with [sphinxcontrib-bibtex](https://sphinxcontrib-bibtex.readthedocs.io/) +- the [myst][] extension allows to write documentation in markdown/Markedly Structured Text +- [Numpy-style docstrings][numpydoc] (through the [napoloen][numpydoc-napoleon] extension). +- Jupyter notebooks as tutorials through [myst-nb][] (See [Tutorials with myst-nb](#tutorials-with-myst-nb-and-jupyter-notebooks)) +- [Sphinx autodoc typehints][], to automatically reference annotated input and output types +- Citations (like {cite:p}`Virshup_2023`) can be included with [sphinxcontrib-bibtex](https://sphinxcontrib-bibtex.readthedocs.io/) See the [scanpy developer docs](https://scanpy.readthedocs.io/en/latest/dev/documentation.html) for more information on how to write documentation. @@ -120,10 +120,10 @@ repository. #### Hints -- If you refer to objects from other packages, please add an entry to `intersphinx_mapping` in `docs/conf.py`. Only - if you do so can sphinx automatically create a link to the external documentation. -- If building the documentation fails because of a missing link that is outside your control, you can add an entry to - the `nitpick_ignore` list in `docs/conf.py` +- If you refer to objects from other packages, please add an entry to `intersphinx_mapping` in `docs/conf.py`. Only + if you do so can sphinx automatically create a link to the external documentation. +- If building the documentation fails because of a missing link that is outside your control, you can add an entry to + the `nitpick_ignore` list in `docs/conf.py` #### Building the docs locally From 87d57926bc2660d05eb960804823e30726ebbd0b Mon Sep 17 00:00:00 2001 From: Luca Marconato Date: Tue, 17 Dec 2024 18:25:37 +0100 Subject: [PATCH 4/8] fix iterable type --- src/spatialdata_plot/pl/basic.py | 3 ++- src/spatialdata_plot/pl/render.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/spatialdata_plot/pl/basic.py b/src/spatialdata_plot/pl/basic.py index d23b9710..f7cb5abe 100644 --- a/src/spatialdata_plot/pl/basic.py +++ b/src/spatialdata_plot/pl/basic.py @@ -948,7 +948,8 @@ def show( if wanted_labels_on_this_cs: if (table := params_copy.table_name) is not None: - colors = sc.get.obs_df(sdata[table], params_copy.color) + keys = [params_copy.color] if not isinstance(params_copy.color, list) else params_copy.color + colors = sc.get.obs_df(sdata[table], keys) if isinstance(colors.dtype, pd.CategoricalDtype): _maybe_set_colors( source=sdata[table], diff --git a/src/spatialdata_plot/pl/render.py b/src/spatialdata_plot/pl/render.py index a8a07058..1eafa3d6 100644 --- a/src/spatialdata_plot/pl/render.py +++ b/src/spatialdata_plot/pl/render.py @@ -439,7 +439,8 @@ def _render_points( ) if col_for_color is not None: - cols = sc.get.obs_df(adata, col_for_color) + keys = [col_for_color] if not isinstance(col_for_color, list) else col_for_color + cols = sc.get.obs_df(adata, keys) # maybe set color based on type if isinstance(cols.dtype, pd.CategoricalDtype): _maybe_set_colors( From 2edc11c1bc95dd78f93fa2e169fc954a7fd9fd25 Mon Sep 17 00:00:00 2001 From: Luca Marconato Date: Tue, 17 Dec 2024 18:50:47 +0100 Subject: [PATCH 5/8] fix --- src/spatialdata_plot/pl/basic.py | 3 ++- src/spatialdata_plot/pl/render.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/spatialdata_plot/pl/basic.py b/src/spatialdata_plot/pl/basic.py index ec9b6130..f1b83556 100644 --- a/src/spatialdata_plot/pl/basic.py +++ b/src/spatialdata_plot/pl/basic.py @@ -951,8 +951,9 @@ def show( if wanted_labels_on_this_cs: if (table := params_copy.table_name) is not None: keys = [params_copy.color] if not isinstance(params_copy.color, list) else params_copy.color + assert len(keys) == 1 colors = sc.get.obs_df(sdata[table], keys) - if isinstance(colors.dtype, pd.CategoricalDtype): + if isinstance(colors[keys[0]].dtype, pd.CategoricalDtype): _maybe_set_colors( source=sdata[table], target=sdata[table], diff --git a/src/spatialdata_plot/pl/render.py b/src/spatialdata_plot/pl/render.py index d1a92a8c..ae9f240d 100644 --- a/src/spatialdata_plot/pl/render.py +++ b/src/spatialdata_plot/pl/render.py @@ -454,9 +454,10 @@ def _render_points( if col_for_color is not None: keys = [col_for_color] if not isinstance(col_for_color, list) else col_for_color + assert len(keys) == 1 cols = sc.get.obs_df(adata, keys) # maybe set color based on type - if isinstance(cols.dtype, pd.CategoricalDtype): + if isinstance(cols[keys[0]].dtype, pd.CategoricalDtype): _maybe_set_colors( source=adata, target=adata, From 48a4331b785fa166de7aba4ae72f54637f92fa71 Mon Sep 17 00:00:00 2001 From: Luca Marconato Date: Wed, 18 Dec 2024 16:51:29 +0100 Subject: [PATCH 6/8] simplify code --- CHANGELOG.md | 124 +++++++++++++++--------------- README.md | 4 +- docs/contributing.md | 18 ++--- src/spatialdata_plot/pl/basic.py | 7 +- src/spatialdata_plot/pl/render.py | 7 +- tests/pl/test_render_points.py | 9 +++ 6 files changed, 88 insertions(+), 81 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a866e14..5b47acbf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,167 +12,167 @@ and this project adheres to [Semantic Versioning][]. ### Fixed -- Transformations of Points and Shapes are now applied before rendering with datashader (#378) -- Fix bug due to `sc.get.obs_df()` returning a different type (#393) +- Transformations of Points and Shapes are now applied before rendering with datashader (#378) +- Fix bug due to `sc.get.obs_df()` returning a different type (#393) ## [0.2.8] - 2024-11-26 ### Changed -- Support for `xarray.DataTree` (which moved from `datatree.DataTree`) (#380) +- Support for `xarray.DataTree` (which moved from `datatree.DataTree`) (#380) ## [0.2.7] - 2024-10-24 ### Added -- The user can now specify `datashader_reduction` to control the rendering behaviour (#309) -- Rendering outlines of shapes with datashader works now (#309) +- The user can now specify `datashader_reduction` to control the rendering behaviour (#309) +- Rendering outlines of shapes with datashader works now (#309) ### Fixed -- datashader now uses canvas size = image size which speeds up the rendering (#309) -- datashader now uses the `linear` as interpolation method for colormaps instead of the default `eq_hist` to make it equivalent to matplotlib (#309) -- point sizes of datashader now agree with matplotlib also when dpi != 100 (#309) -- Giving a custom colormap when rendering a multiscale image now works (#586) +- datashader now uses canvas size = image size which speeds up the rendering (#309) +- datashader now uses the `linear` as interpolation method for colormaps instead of the default `eq_hist` to make it equivalent to matplotlib (#309) +- point sizes of datashader now agree with matplotlib also when dpi != 100 (#309) +- Giving a custom colormap when rendering a multiscale image now works (#586) ## [0.2.6] - 2024-09-04 ### Changed -- Lowered RMSE-threshold for plot-based tests from 45 to 15 (#344) -- When subsetting to `groups`, `NA` isn't automatically added to legend (#344) -- When rendering a single image channel, a colorbar is now shown (#346) -- Removed `percentiles_for_norm` parameter (#346) -- Changed `norm` to no longer accept bools, only `mpl.colors.Normalise` or `None` (#346) +- Lowered RMSE-threshold for plot-based tests from 45 to 15 (#344) +- When subsetting to `groups`, `NA` isn't automatically added to legend (#344) +- When rendering a single image channel, a colorbar is now shown (#346) +- Removed `percentiles_for_norm` parameter (#346) +- Changed `norm` to no longer accept bools, only `mpl.colors.Normalise` or `None` (#346) ### Fixed -- Filtering with `groups` now preserves original cmap (#344) -- Non-selected `groups` are now not shown in `na_color` (#344) -- Several issues associated with `norm` and `colorbar` (#346) +- Filtering with `groups` now preserves original cmap (#344) +- Non-selected `groups` are now not shown in `na_color` (#344) +- Several issues associated with `norm` and `colorbar` (#346) ## [0.2.5] - 2024-08-23 ### Changed -- Replaced `outline` parameter in `render_labels` with alpha-based logic (#323) -- Lowered RMSE-threshold for plot-based tests from 60 to 45 (#323) -- Removed `preprocessing` (.pp) accessor (#329) +- Replaced `outline` parameter in `render_labels` with alpha-based logic (#323) +- Lowered RMSE-threshold for plot-based tests from 60 to 45 (#323) +- Removed `preprocessing` (.pp) accessor (#329) ### Fixed -- Minor fixes for several tests as a result of the threshold change (#323) +- Minor fixes for several tests as a result of the threshold change (#323) ## [0.2.4] - 2024-08-07 ### Added -- Added utils function for 0-transparent cmaps (#302) +- Added utils function for 0-transparent cmaps (#302) ### Fixed -- Took RNG out of categorical label test (#306) -- Performance bug when plotting shapes (#298) -- scale parameter was ignored for single-scale images (#301) -- Changes to support for dask-expr (#283) -- Added error handling for non-existent elements (#305) -- Specifying vmin and vmax properly clips image data (#307) -- import bug `get_cmap()` (8fd969c) +- Took RNG out of categorical label test (#306) +- Performance bug when plotting shapes (#298) +- scale parameter was ignored for single-scale images (#301) +- Changes to support for dask-expr (#283) +- Added error handling for non-existent elements (#305) +- Specifying vmin and vmax properly clips image data (#307) +- import bug `get_cmap()` (8fd969c) ## [0.2.3] - 2024-07-03 ### Added -- Datashader support for points and shapes (#244) +- Datashader support for points and shapes (#244) ### Changed -- All parameters are now provided for a single element (#272) +- All parameters are now provided for a single element (#272) ### Fixed -- Fix color assignment for NaN values (#257) -- Zorder of rendering now strictly follows the order of the render_x calls (#244) +- Fix color assignment for NaN values (#257) +- 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 (#236) -- Fix channel str support (#221) +- Fixed `fill_alpha` ignoring `alpha` channel from custom cmap (#236) +- Fix channel str support (#221) ## [0.2.1] - 2024-03-26 ### Minor -- Adjusted GitHub worklows +- Adjusted GitHub worklows ## [0.2.0] - 2024-03-24 ### Added -- Support for plotting multiple tables @melonora +- Support for plotting multiple tables @melonora ### Fixed -- Several bugfixes, especially for colors and palettes @melonora +- Several bugfixes, especially for colors and palettes @melonora ## [0.1.0] - 2024-01-17 ### Added -- Multiscale image handling: user can specify a scale, else the best scale is selected automatically given the figure size and dpi (#164) -- Large images are automatically rasterized to speed up performance (#164) -- Added better error message for mismatch in cs and ax number (#185) -- Beter test coverage for correct plotting of elements after transformation (#198) -- Can now stack render commands (#190, #192) -- The `color` argument in render_shapes/points now accepts actual colors as well (#199) -- Input arguments are now evaulated for their types in basic.py (#199) +- Multiscale image handling: user can specify a scale, else the best scale is selected automatically given the figure size and dpi (#164) +- Large images are automatically rasterized to speed up performance (#164) +- Added better error message for mismatch in cs and ax number (#185) +- Beter test coverage for correct plotting of elements after transformation (#198) +- Can now stack render commands (#190, #192) +- The `color` argument in render_shapes/points now accepts actual colors as well (#199) +- Input arguments are now evaulated for their types in basic.py (#199) ### Fixed -- Now dropping index when plotting shapes after spatial query (#177) -- Points are now being correctly rotated (#198) -- 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) +- Now dropping index when plotting shapes after spatial query (#177) +- Points are now being correctly rotated (#198) +- 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) ## [0.0.6] - 2023-11-06 ### Added -- Pushed `get_extent` functionality upstream to `spatialdata` (#162) +- Pushed `get_extent` functionality upstream to `spatialdata` (#162) ## [0.0.5] - 2023-10-02 ### Added -- Can now scale shapes (#152) -- Can now plot columns from GeoDataFrame (#149) +- Can now scale shapes (#152) +- Can now plot columns from GeoDataFrame (#149) ### Fixed -- Multipolygons are now handled correctly (#93) -- Legend order is now deterministic (#143) -- Images no longer normalised by default (#150) -- Filtering of shapes and points using the `groups` argument is now possible, coloring by palette and cmap arguments works for shapes and points (#153) -- Colorbar no longer autoscales to [0, 1] (#155) -- Plotting shapes after a spatial query is now possible (#163) +- Multipolygons are now handled correctly (#93) +- Legend order is now deterministic (#143) +- Images no longer normalised by default (#150) +- Filtering of shapes and points using the `groups` argument is now possible, coloring by palette and cmap arguments works for shapes and points (#153) +- Colorbar no longer autoscales to [0, 1] (#155) +- Plotting shapes after a spatial query is now possible (#163) ## [0.0.4] - 2023-08-11 ### Fixed -- Multi-scale images/labels are now correctly substituted and the action is logged (#131). -- Empty geometries among the shapes can be handeled (#133). -- `outline_width` parameter in render_shapes is now a float that actually determines the line width (#139). +- Multi-scale images/labels are now correctly substituted and the action is logged (#131). +- Empty geometries among the shapes can be handeled (#133). +- `outline_width` parameter in render_shapes is now a float that actually determines the line width (#139). ## [0.0.2] - 2023-06-25 ### Fixed -- Multiple bugfixes of which I didn't keep track of. +- Multiple bugfixes of which I didn't keep track of. ## [0.0.1] - 2023-04-04 ### Added -- Initial release of `spatialdata-plot` with support for `images`, `labels`, `points` and `shapes`. +- Initial release of `spatialdata-plot` with support for `images`, `labels`, `points` and `shapes`. diff --git a/README.md b/README.md index ba786da3..5dc823a5 100644 --- a/README.md +++ b/README.md @@ -26,8 +26,8 @@ SpatialData’s plotting capabilities allow to quickly visualise all contained m For more information on the `spatialdata-plot` library, please refer to the [documentation](https://spatialdata.scverse.org/projects/plot/en/latest/index.html). In particular, the -- [API documentation][link-api]. -- [Example notebooks][link-notebooks] (section "Visiualizations") +- [API documentation][link-api]. +- [Example notebooks][link-notebooks] (section "Visiualizations") ## Installation diff --git a/docs/contributing.md b/docs/contributing.md index 77e97aae..66a84688 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -99,11 +99,11 @@ Specify `vX.X.X` as a tag name and create a release. For more information, see [ Please write documentation for new or changed features and use-cases. This project uses [sphinx][] with the following features: -- the [myst][] extension allows to write documentation in markdown/Markedly Structured Text -- [Numpy-style docstrings][numpydoc] (through the [napoloen][numpydoc-napoleon] extension). -- Jupyter notebooks as tutorials through [myst-nb][] (See [Tutorials with myst-nb](#tutorials-with-myst-nb-and-jupyter-notebooks)) -- [Sphinx autodoc typehints][], to automatically reference annotated input and output types -- Citations (like {cite:p}`Virshup_2023`) can be included with [sphinxcontrib-bibtex](https://sphinxcontrib-bibtex.readthedocs.io/) +- the [myst][] extension allows to write documentation in markdown/Markedly Structured Text +- [Numpy-style docstrings][numpydoc] (through the [napoloen][numpydoc-napoleon] extension). +- Jupyter notebooks as tutorials through [myst-nb][] (See [Tutorials with myst-nb](#tutorials-with-myst-nb-and-jupyter-notebooks)) +- [Sphinx autodoc typehints][], to automatically reference annotated input and output types +- Citations (like {cite:p}`Virshup_2023`) can be included with [sphinxcontrib-bibtex](https://sphinxcontrib-bibtex.readthedocs.io/) See the [scanpy developer docs](https://scanpy.readthedocs.io/en/latest/dev/documentation.html) for more information on how to write documentation. @@ -120,10 +120,10 @@ repository. #### Hints -- If you refer to objects from other packages, please add an entry to `intersphinx_mapping` in `docs/conf.py`. Only - if you do so can sphinx automatically create a link to the external documentation. -- If building the documentation fails because of a missing link that is outside your control, you can add an entry to - the `nitpick_ignore` list in `docs/conf.py` +- If you refer to objects from other packages, please add an entry to `intersphinx_mapping` in `docs/conf.py`. Only + if you do so can sphinx automatically create a link to the external documentation. +- If building the documentation fails because of a missing link that is outside your control, you can add an entry to + the `nitpick_ignore` list in `docs/conf.py` #### Building the docs locally diff --git a/src/spatialdata_plot/pl/basic.py b/src/spatialdata_plot/pl/basic.py index f1b83556..d68f0db3 100644 --- a/src/spatialdata_plot/pl/basic.py +++ b/src/spatialdata_plot/pl/basic.py @@ -950,10 +950,9 @@ def show( if wanted_labels_on_this_cs: if (table := params_copy.table_name) is not None: - keys = [params_copy.color] if not isinstance(params_copy.color, list) else params_copy.color - assert len(keys) == 1 - colors = sc.get.obs_df(sdata[table], keys) - if isinstance(colors[keys[0]].dtype, pd.CategoricalDtype): + assert isinstance(params_copy.color, str) + colors = sc.get.obs_df(sdata[table], [params_copy.color]) + if isinstance(colors[params_copy.color].dtype, pd.CategoricalDtype): _maybe_set_colors( source=sdata[table], target=sdata[table], diff --git a/src/spatialdata_plot/pl/render.py b/src/spatialdata_plot/pl/render.py index ae9f240d..7ff110d0 100644 --- a/src/spatialdata_plot/pl/render.py +++ b/src/spatialdata_plot/pl/render.py @@ -453,11 +453,10 @@ def _render_points( ) if col_for_color is not None: - keys = [col_for_color] if not isinstance(col_for_color, list) else col_for_color - assert len(keys) == 1 - cols = sc.get.obs_df(adata, keys) + assert isinstance(col_for_color, str) + cols = sc.get.obs_df(adata, [col_for_color]) # maybe set color based on type - if isinstance(cols[keys[0]].dtype, pd.CategoricalDtype): + if isinstance(cols[col_for_color].dtype, pd.CategoricalDtype): _maybe_set_colors( source=adata, target=adata, diff --git a/tests/pl/test_render_points.py b/tests/pl/test_render_points.py index e3e99099..73d020a2 100644 --- a/tests/pl/test_render_points.py +++ b/tests/pl/test_render_points.py @@ -5,6 +5,7 @@ import matplotlib.pyplot as plt import numpy as np import pandas as pd +import pytest import scanpy as sc from anndata import AnnData from spatialdata import SpatialData, deepcopy @@ -106,6 +107,14 @@ def test_plot_points_categorical_color(self, sdata_blobs: SpatialData): sdata_blobs["other_table"].obs["category"] = sdata_blobs["other_table"].obs["category"].astype("category") sdata_blobs.pl.render_points("blobs_points", color="category").pl.show() + @pytest.mark.parametrize("method", ["matplotlib", "datashader"]) + def test_plot_points_categorical_color_column(self, sdata_blobs: SpatialData, method: str): + sdata_blobs.pl.render_points("blobs_points", color="genes", method=method).pl.show() + + @pytest.mark.parametrize("method", ["matplotlib", "datashader"]) + def test_plot_points_continuous_color_column(self, sdata_blobs: SpatialData, method: str): + sdata_blobs.pl.render_points("blobs_points", color="instance_id", method=method).pl.show() + def test_plot_datashader_continuous_color(self, sdata_blobs: SpatialData): sdata_blobs.pl.render_points( element="blobs_points", size=40, color="instance_id", alpha=0.6, method="datashader" From 2a4b59b37a04c96c9f2fcf05a087704996eb82d4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 18 Dec 2024 15:51:53 +0000 Subject: [PATCH 7/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- CHANGELOG.md | 124 +++++++++++++++++++++---------------------- README.md | 4 +- docs/contributing.md | 18 +++---- 3 files changed, 73 insertions(+), 73 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b47acbf..9a866e14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,167 +12,167 @@ and this project adheres to [Semantic Versioning][]. ### Fixed -- Transformations of Points and Shapes are now applied before rendering with datashader (#378) -- Fix bug due to `sc.get.obs_df()` returning a different type (#393) +- Transformations of Points and Shapes are now applied before rendering with datashader (#378) +- Fix bug due to `sc.get.obs_df()` returning a different type (#393) ## [0.2.8] - 2024-11-26 ### Changed -- Support for `xarray.DataTree` (which moved from `datatree.DataTree`) (#380) +- Support for `xarray.DataTree` (which moved from `datatree.DataTree`) (#380) ## [0.2.7] - 2024-10-24 ### Added -- The user can now specify `datashader_reduction` to control the rendering behaviour (#309) -- Rendering outlines of shapes with datashader works now (#309) +- The user can now specify `datashader_reduction` to control the rendering behaviour (#309) +- Rendering outlines of shapes with datashader works now (#309) ### Fixed -- datashader now uses canvas size = image size which speeds up the rendering (#309) -- datashader now uses the `linear` as interpolation method for colormaps instead of the default `eq_hist` to make it equivalent to matplotlib (#309) -- point sizes of datashader now agree with matplotlib also when dpi != 100 (#309) -- Giving a custom colormap when rendering a multiscale image now works (#586) +- datashader now uses canvas size = image size which speeds up the rendering (#309) +- datashader now uses the `linear` as interpolation method for colormaps instead of the default `eq_hist` to make it equivalent to matplotlib (#309) +- point sizes of datashader now agree with matplotlib also when dpi != 100 (#309) +- Giving a custom colormap when rendering a multiscale image now works (#586) ## [0.2.6] - 2024-09-04 ### Changed -- Lowered RMSE-threshold for plot-based tests from 45 to 15 (#344) -- When subsetting to `groups`, `NA` isn't automatically added to legend (#344) -- When rendering a single image channel, a colorbar is now shown (#346) -- Removed `percentiles_for_norm` parameter (#346) -- Changed `norm` to no longer accept bools, only `mpl.colors.Normalise` or `None` (#346) +- Lowered RMSE-threshold for plot-based tests from 45 to 15 (#344) +- When subsetting to `groups`, `NA` isn't automatically added to legend (#344) +- When rendering a single image channel, a colorbar is now shown (#346) +- Removed `percentiles_for_norm` parameter (#346) +- Changed `norm` to no longer accept bools, only `mpl.colors.Normalise` or `None` (#346) ### Fixed -- Filtering with `groups` now preserves original cmap (#344) -- Non-selected `groups` are now not shown in `na_color` (#344) -- Several issues associated with `norm` and `colorbar` (#346) +- Filtering with `groups` now preserves original cmap (#344) +- Non-selected `groups` are now not shown in `na_color` (#344) +- Several issues associated with `norm` and `colorbar` (#346) ## [0.2.5] - 2024-08-23 ### Changed -- Replaced `outline` parameter in `render_labels` with alpha-based logic (#323) -- Lowered RMSE-threshold for plot-based tests from 60 to 45 (#323) -- Removed `preprocessing` (.pp) accessor (#329) +- Replaced `outline` parameter in `render_labels` with alpha-based logic (#323) +- Lowered RMSE-threshold for plot-based tests from 60 to 45 (#323) +- Removed `preprocessing` (.pp) accessor (#329) ### Fixed -- Minor fixes for several tests as a result of the threshold change (#323) +- Minor fixes for several tests as a result of the threshold change (#323) ## [0.2.4] - 2024-08-07 ### Added -- Added utils function for 0-transparent cmaps (#302) +- Added utils function for 0-transparent cmaps (#302) ### Fixed -- Took RNG out of categorical label test (#306) -- Performance bug when plotting shapes (#298) -- scale parameter was ignored for single-scale images (#301) -- Changes to support for dask-expr (#283) -- Added error handling for non-existent elements (#305) -- Specifying vmin and vmax properly clips image data (#307) -- import bug `get_cmap()` (8fd969c) +- Took RNG out of categorical label test (#306) +- Performance bug when plotting shapes (#298) +- scale parameter was ignored for single-scale images (#301) +- Changes to support for dask-expr (#283) +- Added error handling for non-existent elements (#305) +- Specifying vmin and vmax properly clips image data (#307) +- import bug `get_cmap()` (8fd969c) ## [0.2.3] - 2024-07-03 ### Added -- Datashader support for points and shapes (#244) +- Datashader support for points and shapes (#244) ### Changed -- All parameters are now provided for a single element (#272) +- All parameters are now provided for a single element (#272) ### Fixed -- Fix color assignment for NaN values (#257) -- Zorder of rendering now strictly follows the order of the render_x calls (#244) +- Fix color assignment for NaN values (#257) +- 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 (#236) -- Fix channel str support (#221) +- Fixed `fill_alpha` ignoring `alpha` channel from custom cmap (#236) +- Fix channel str support (#221) ## [0.2.1] - 2024-03-26 ### Minor -- Adjusted GitHub worklows +- Adjusted GitHub worklows ## [0.2.0] - 2024-03-24 ### Added -- Support for plotting multiple tables @melonora +- Support for plotting multiple tables @melonora ### Fixed -- Several bugfixes, especially for colors and palettes @melonora +- Several bugfixes, especially for colors and palettes @melonora ## [0.1.0] - 2024-01-17 ### Added -- Multiscale image handling: user can specify a scale, else the best scale is selected automatically given the figure size and dpi (#164) -- Large images are automatically rasterized to speed up performance (#164) -- Added better error message for mismatch in cs and ax number (#185) -- Beter test coverage for correct plotting of elements after transformation (#198) -- Can now stack render commands (#190, #192) -- The `color` argument in render_shapes/points now accepts actual colors as well (#199) -- Input arguments are now evaulated for their types in basic.py (#199) +- Multiscale image handling: user can specify a scale, else the best scale is selected automatically given the figure size and dpi (#164) +- Large images are automatically rasterized to speed up performance (#164) +- Added better error message for mismatch in cs and ax number (#185) +- Beter test coverage for correct plotting of elements after transformation (#198) +- Can now stack render commands (#190, #192) +- The `color` argument in render_shapes/points now accepts actual colors as well (#199) +- Input arguments are now evaulated for their types in basic.py (#199) ### Fixed -- Now dropping index when plotting shapes after spatial query (#177) -- Points are now being correctly rotated (#198) -- 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) +- Now dropping index when plotting shapes after spatial query (#177) +- Points are now being correctly rotated (#198) +- 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) ## [0.0.6] - 2023-11-06 ### Added -- Pushed `get_extent` functionality upstream to `spatialdata` (#162) +- Pushed `get_extent` functionality upstream to `spatialdata` (#162) ## [0.0.5] - 2023-10-02 ### Added -- Can now scale shapes (#152) -- Can now plot columns from GeoDataFrame (#149) +- Can now scale shapes (#152) +- Can now plot columns from GeoDataFrame (#149) ### Fixed -- Multipolygons are now handled correctly (#93) -- Legend order is now deterministic (#143) -- Images no longer normalised by default (#150) -- Filtering of shapes and points using the `groups` argument is now possible, coloring by palette and cmap arguments works for shapes and points (#153) -- Colorbar no longer autoscales to [0, 1] (#155) -- Plotting shapes after a spatial query is now possible (#163) +- Multipolygons are now handled correctly (#93) +- Legend order is now deterministic (#143) +- Images no longer normalised by default (#150) +- Filtering of shapes and points using the `groups` argument is now possible, coloring by palette and cmap arguments works for shapes and points (#153) +- Colorbar no longer autoscales to [0, 1] (#155) +- Plotting shapes after a spatial query is now possible (#163) ## [0.0.4] - 2023-08-11 ### Fixed -- Multi-scale images/labels are now correctly substituted and the action is logged (#131). -- Empty geometries among the shapes can be handeled (#133). -- `outline_width` parameter in render_shapes is now a float that actually determines the line width (#139). +- Multi-scale images/labels are now correctly substituted and the action is logged (#131). +- Empty geometries among the shapes can be handeled (#133). +- `outline_width` parameter in render_shapes is now a float that actually determines the line width (#139). ## [0.0.2] - 2023-06-25 ### Fixed -- Multiple bugfixes of which I didn't keep track of. +- Multiple bugfixes of which I didn't keep track of. ## [0.0.1] - 2023-04-04 ### Added -- Initial release of `spatialdata-plot` with support for `images`, `labels`, `points` and `shapes`. +- Initial release of `spatialdata-plot` with support for `images`, `labels`, `points` and `shapes`. diff --git a/README.md b/README.md index 5dc823a5..ba786da3 100644 --- a/README.md +++ b/README.md @@ -26,8 +26,8 @@ SpatialData’s plotting capabilities allow to quickly visualise all contained m For more information on the `spatialdata-plot` library, please refer to the [documentation](https://spatialdata.scverse.org/projects/plot/en/latest/index.html). In particular, the -- [API documentation][link-api]. -- [Example notebooks][link-notebooks] (section "Visiualizations") +- [API documentation][link-api]. +- [Example notebooks][link-notebooks] (section "Visiualizations") ## Installation diff --git a/docs/contributing.md b/docs/contributing.md index 66a84688..77e97aae 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -99,11 +99,11 @@ Specify `vX.X.X` as a tag name and create a release. For more information, see [ Please write documentation for new or changed features and use-cases. This project uses [sphinx][] with the following features: -- the [myst][] extension allows to write documentation in markdown/Markedly Structured Text -- [Numpy-style docstrings][numpydoc] (through the [napoloen][numpydoc-napoleon] extension). -- Jupyter notebooks as tutorials through [myst-nb][] (See [Tutorials with myst-nb](#tutorials-with-myst-nb-and-jupyter-notebooks)) -- [Sphinx autodoc typehints][], to automatically reference annotated input and output types -- Citations (like {cite:p}`Virshup_2023`) can be included with [sphinxcontrib-bibtex](https://sphinxcontrib-bibtex.readthedocs.io/) +- the [myst][] extension allows to write documentation in markdown/Markedly Structured Text +- [Numpy-style docstrings][numpydoc] (through the [napoloen][numpydoc-napoleon] extension). +- Jupyter notebooks as tutorials through [myst-nb][] (See [Tutorials with myst-nb](#tutorials-with-myst-nb-and-jupyter-notebooks)) +- [Sphinx autodoc typehints][], to automatically reference annotated input and output types +- Citations (like {cite:p}`Virshup_2023`) can be included with [sphinxcontrib-bibtex](https://sphinxcontrib-bibtex.readthedocs.io/) See the [scanpy developer docs](https://scanpy.readthedocs.io/en/latest/dev/documentation.html) for more information on how to write documentation. @@ -120,10 +120,10 @@ repository. #### Hints -- If you refer to objects from other packages, please add an entry to `intersphinx_mapping` in `docs/conf.py`. Only - if you do so can sphinx automatically create a link to the external documentation. -- If building the documentation fails because of a missing link that is outside your control, you can add an entry to - the `nitpick_ignore` list in `docs/conf.py` +- If you refer to objects from other packages, please add an entry to `intersphinx_mapping` in `docs/conf.py`. Only + if you do so can sphinx automatically create a link to the external documentation. +- If building the documentation fails because of a missing link that is outside your control, you can add an entry to + the `nitpick_ignore` list in `docs/conf.py` #### Building the docs locally From 3c9062d2b9197b6e8f9c3852ded67ed456e26729 Mon Sep 17 00:00:00 2001 From: Luca Marconato Date: Wed, 18 Dec 2024 16:59:32 +0100 Subject: [PATCH 8/8] removed extra tests --- tests/pl/test_render_points.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/tests/pl/test_render_points.py b/tests/pl/test_render_points.py index 73d020a2..e3e99099 100644 --- a/tests/pl/test_render_points.py +++ b/tests/pl/test_render_points.py @@ -5,7 +5,6 @@ import matplotlib.pyplot as plt import numpy as np import pandas as pd -import pytest import scanpy as sc from anndata import AnnData from spatialdata import SpatialData, deepcopy @@ -107,14 +106,6 @@ def test_plot_points_categorical_color(self, sdata_blobs: SpatialData): sdata_blobs["other_table"].obs["category"] = sdata_blobs["other_table"].obs["category"].astype("category") sdata_blobs.pl.render_points("blobs_points", color="category").pl.show() - @pytest.mark.parametrize("method", ["matplotlib", "datashader"]) - def test_plot_points_categorical_color_column(self, sdata_blobs: SpatialData, method: str): - sdata_blobs.pl.render_points("blobs_points", color="genes", method=method).pl.show() - - @pytest.mark.parametrize("method", ["matplotlib", "datashader"]) - def test_plot_points_continuous_color_column(self, sdata_blobs: SpatialData, method: str): - sdata_blobs.pl.render_points("blobs_points", color="instance_id", method=method).pl.show() - def test_plot_datashader_continuous_color(self, sdata_blobs: SpatialData): sdata_blobs.pl.render_points( element="blobs_points", size=40, color="instance_id", alpha=0.6, method="datashader"