-
Notifications
You must be signed in to change notification settings - Fork 13
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
issues with plotting multipolygons #72
Comments
Hey there! Sorry, only now seeing the issue. Yeah, will be supported in the future. I'm currently trying to reproduce your error and will then fix it.
Since you said that information would be lost, I'm assuming you have the "(shell, holes)" case, f.e., to label only the cytoplasm. Very happy to support that case as it seems super useful. From now on I'll just assume you meant that scenario. MRE
|
@berombau provided example CellPose output which produces MultiPolygons -> https://dl01.irc.ugent.be/spatial/geojsons/adataA1-1.geojson Can we used with
|
Although spatialData supports multipolygons, plt.shapes doesn't support it.
When running following code (where sdate.shapes contains multipolygons):
'''
import spatialdata_plot
sdata.pl.render_images('raw_image').pl.render_shapes().pl.show()
'''
Following error is produced:
AttributeError Traceback (most recent call last)
Input In [58], in <cell line: 2>()
1 import spatialdata_plot
----> 2 sdata.pl.render_images('raw_image').pl.render_shapes().pl.show()
File /srv/scratch/lottep/anaconda3/envs/napari-spongepy/lib/python3.10/site-packages/spatialdata_plot/pl/basic.py:625, in PlotAccessor.show(self, coordinate_systems, legend_fontsize, legend_fontweight, legend_loc, legend_fontoutline, na_in_legend, colorbar, wspace, hspace, ncols, frameon, figsize, dpi, fig, ax, return_ax, save)
618 if is_categorical_dtype(colors):
619 _maybe_set_colors(
620 source=sdata.table,
621 target=sdata.table,
622 key=params.color,
623 palette=params.palette,
624 )
--> 625 _render_shapes(
626 sdata=sdata,
627 render_params=params,
628 coordinate_system=cs,
629 ax=ax,
630 fig_params=fig_params,
631 scalebar_params=scalebar_params,
632 legend_params=legend_params,
633 )
635 elif cmd == "render_points" and cs_contents.query(f"cs == '{cs}'")["has_points"][0]:
636 _render_points(
637 sdata=sdata,
638 render_params=params,
(...)
643 legend_params=legend_params,
644 )
File /srv/scratch/lottep/anaconda3/envs/napari-spongepy/lib/python3.10/site-packages/spatialdata_plot/pl/render.py:154, in _render_shapes(sdata, render_params, coordinate_system, ax, fig_params, scalebar_params, legend_params)
151 if len(color_vector) == 0:
152 color_vector = [(0.83, 0.83, 0.83, 1.0)]
--> 154 _cax = _get_collection_shape(
155 shapes=shapes,
156 s=render_params.size,
157 c=color_vector,
158 rasterized=sc_settings._vector_friendly,
159 cmap=render_params.cmap_params.cmap,
160 norm=norm,
161 alpha=render_params.alpha,
162 # **kwargs,
163 )
164 cax = ax.add_collection(_cax)
166 _ = _decorate_axs(
167 ax=ax,
168 cax=cax,
(...)
184 # scalebar_kwargs=scalebar_params.scalebar_kwargs,
185 )
File /srv/scratch/lottep/anaconda3/envs/napari-spongepy/lib/python3.10/site-packages/spatialdata_plot/pl/render.py:109, in _render_shapes.._get_collection_shape(shapes, c, s, norm, **kwargs)
107 """Get collection of shapes."""
108 if shapes["geometry"].iloc[0].geom_type == "Polygon":
--> 109 patches = [Polygon(p.exterior.coords, closed=False) for p in shapes["geometry"]]
110 elif shapes["geometry"].iloc[0].geom_type == "Point":
111 patches = [Circle((circ.x, circ.y), radius=r * s) for circ, r in zip(shapes["geometry"], shapes["radius"])]
File /srv/scratch/lottep/anaconda3/envs/napari-spongepy/lib/python3.10/site-packages/spatialdata_plot/pl/render.py:109, in (.0)
107 """Get collection of shapes."""
108 if shapes["geometry"].iloc[0].geom_type == "Polygon":
--> 109 patches = [Polygon(p.exterior.coords, closed=False) for p in shapes["geometry"]]
110 elif shapes["geometry"].iloc[0].geom_type == "Point":
111 patches = [Circle((circ.x, circ.y), radius=r * s) for circ, r in zip(shapes["geometry"], shapes["radius"])]
AttributeError: 'MultiPolygon' object has no attribute 'exterior'
Will multipolygons will be supported for plotting in the future or should I try to make them into polygons? (and thus losing information)?
The text was updated successfully, but these errors were encountered: