mechanochat.plotting.alphashape_plot#

mechanochat.plotting.alphashape_plot(sem: SEM2, vis_key: str | None = None, obsm_key: str | None = None, arr: ndarray[Any, dtype[_ScalarType_co]] | Series | None = None, summary: str = 'receiver_mechano_signal', compute_alphashape: bool = False, cid_list: ndarray[Any, dtype[int64]] | ndarray[Any, dtype[bool_]] | Sequence[int] | None = None, cmap_name: str = 'Reds', palette: Dict[str, Tuple] | None = None, vmax: float | None = None, vmin: float | None = None, boundary_width: float = 0.5, boundary_color: tuple[float, float, float] | str | tuple[float, float, float, float] | tuple[tuple[float, float, float] | str, float] | tuple[tuple[float, float, float, float], float] | None = 'gray', boundary_alpha: float = 1, face_color: str | ndarray[Any, dtype[floating]] | Sequence[float] | None = None, face_alpha: float | Iterable[float] = 1, show_axis: bool = False, enable_annotation: bool = False, enable_legend: bool = True, enable_colorbar: bool = True, return_mappable: bool = False, ax: Axes | None = None, show: bool = True, save_name: str | None = None, rotation: Dict | None = None, **kwargs)[source]#

Plot cell shape using alpha shape, visualize cell data by colors.

Parameters:
  • sem (SEM) – Subcellular element method object

  • vis_key (str, optional) – Key to retrieve visualization data from sem.adata

  • obsm_key (str, optional) – Key of the signal DataFrame in adata.obsm used when summary == ‘cell’

  • arr (np.ndarray or pd.Series, optional) –

    Data for visualization. shape = (nc,) or (len(cid_list),)

    Ignored if vis_key is provided .

    sem.ctype will be visualized if arr and vis_key both are not provided.

  • summary (str) –

    if summary == ‘gene’, retrieve data from adata[:, vis_key]

    if summary == ‘cell’, retrieve data from adata.obs[vis_key]

    if summary in adata.obsm, retrieve data from adata.obsm[summary][vis_key]

  • compute_alphashape (bool, default False) – Compute alphashape if True

  • cid_list (ndarray, optional) – Array of index for cells to be visualized. Default: all cells

  • cmap_name (str, default 'Reds') – Valid matplotlib colormap name to visualize data

  • palette (dict, optional) – Category -> color mapping used for categorical data instead of the colors stored in adata.uns[f’{vis_key}_colors’]

  • vmax (float, optional) – Colormap upper bound. Default: 95th percentile for positive data

  • vmin (float, optional) – Colormap lower bound. Default: data min

  • boundary_width (float, default 1) – Cell boundary line width

  • boundary_color (str or tuple, default 'gray') – Cell boundary line color. Set to None to let each boundary match its face color

  • boundary_alpha (float, default 1) – Cell boundary line opacity, 0 (fully transparent), 1 (fully opaque)

  • face_color (str, ndarray or sequence, optional) – Single color (or one color per cell) overriding the cell type colors. Setting it disables the legend

  • face_alpha (float, default 1) – Cell shape face opacity, 0 (fully transparent), 1 (fully opaque)

  • show_axis (bool, default True) – Show axis

  • enable_annotation (bool, default False) – Annotate cells with index at centroids

  • enable_legend (bool, default False) – Show categorical legend (only for category data)

  • enable_colorbar (bool, default False) – Show colorbar (only for continuous data)

  • return_mappable (bool, default False) – Whether to return the colormap and the normalization used

  • ax (Axes, optional) – Target matplotlib axes object. Creates new figure if None.

  • show (bool, default True) – Whether to keep the figure open after saving. Ignored when save_name is None

  • save_name (str, optional) – Output path for figure saving (e.g., ‘figure.pdf’)

  • rotation (dict, optional) – Rotate the coordinates before plotting. Keys: ‘center’ (2,) and ‘theta’ (radians)

  • **kwargs – keyword arguments passed to sem.compute_alphashape()

Returns:

  • ax (Axes) – If return_mappable=False

  • (ax, cmap, norm) (tuple) – If return_mappable=True. cmap and norm are None when a categorical variable was plotted