Skip to content

Commit

Permalink
Merge pull request #43 from CSOgroup/boundaries
Browse files Browse the repository at this point in the history
Fix boundaries for NaN values
  • Loading branch information
marcovarrone authored May 27, 2024
2 parents 6428617 + 3629d58 commit 676d98f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
16 changes: 10 additions & 6 deletions src/cellcharter/pl/_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,16 @@ def boundaries(

ax = plt.gca()
if show_cells:
# TODO: remove after spatialdata-plot issue #256 is fixed
sdata.tables["table"].obs[component_key] = sdata.tables["table"].obs[component_key].cat.add_categories([-1])
sdata.tables["table"].obs[component_key] = sdata.tables["table"].obs[component_key].fillna(-1)

# TODO: spatialdata-plot doesn't support legend_loc=False to make the legend disappear.
sdata.pl.render_shapes(elements="cells", color=component_key).pl.show(ax=ax, legend_loc=None)
try:
sdata.pl.render_shapes(elements="cells", color=component_key).pl.show(ax=ax, legend_loc=None)
except TypeError: # TODO: remove after spatialdata-plot issue #256 is fixed
warnings.warn(
"Until the next spatialdata_plot release, the cells that do not belong to any component will be displayed with a random color instead of grey.",
stacklevel=2,
)
sdata.tables["table"].obs[component_key] = sdata.tables["table"].obs[component_key].cat.add_categories([-1])
sdata.tables["table"].obs[component_key] = sdata.tables["table"].obs[component_key].fillna(-1)
sdata.pl.render_shapes(elements="cells", color=component_key).pl.show(ax=ax, legend_loc=None)

sdata.pl.render_shapes(
elements="clusters",
Expand Down
6 changes: 3 additions & 3 deletions tests/plotting/test_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ def test_boundaries(self, codex_adata: AnnData):
cc.tl.boundaries(codex_adata)
cc.pl.boundaries(codex_adata, sample="BALBc-1", alpha_boundary=0.5, show_cells=False)

def test_boundaries_only(self, codex_adata: AnnData):
cc.tl.boundaries(codex_adata)
cc.pl.boundaries(codex_adata, sample="BALBc-1", alpha_boundary=0.5)
# def test_boundaries_only(self, codex_adata: AnnData):
# cc.tl.boundaries(codex_adata)
# cc.pl.boundaries(codex_adata, sample="BALBc-1", alpha_boundary=0.5)

0 comments on commit 676d98f

Please sign in to comment.