mechanochat.plotting.draw_legend#

mechanochat.plotting.draw_legend(adata: AnnData | None = None, cluster_key: str | None = None, cmap: dict | None = None, ncol: int = 2, loc: str = 'center left', fontsize: float = 14., save_name: str | None = None, cid_list: ndarray[Any, dtype[int64]] | None = None, rename_map: Dict | None = None, ax: Axes | None = None)[source]#

Draw a standalone cell type legend, e.g. one shared by several panels.

Parameters:
  • adata (AnnData, optional) – AnnData with the annotation in .obs[cluster_key] and the colors in .uns[f’{cluster_key}_colors’]. If None, cmap must be given

  • cluster_key (str, optional) – Key of the cell type annotation in .obs

  • cmap (dict, optional) – Explicit category -> color mapping, used when adata is None

  • ncol (int, default 2) – Number of legend columns

  • loc (str, default 'center left') – Matplotlib legend location

  • fontsize (float, default 14.) – Legend font size

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

  • cid_list (ndarray, optional) – Restrict the legend to the categories present in these cells, keeping the original category order. Default: all cells

  • rename_map (dict, optional) – Old name -> displayed name mapping for the categories

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

Returns:

ax (Axes)