thor.pl.single

thor.pl.single(var_name, img_mask, ax=None, vor=None, full_res_im=None, ROI_tuple=None, img_alpha=1, figsize=(5, 5), dpi=500, show_cbar=True, cbar_loc=[1.04, 0.02, 0.05, 0.15], return_fig=False, show=False, **imshow_kwds)[source]

Color the cells or nuclei with one variable, gene name, or any other observable.

Parameters:
  • var_name (str) – Name of the variable to color the cells or nuclei. For example, a gene name, cell type, etc.

  • img_mask (numpy.ndarray) – Image mask filled with the variable values. Should have the same size as full_res_im.

  • ax (matplotlib.axes.Axes, optional) – The Axes object to plot the gene mask. If None, a new figure and Axes will be created.

  • vor (scipy.spatial.Voronoi, optional) – The Voronoi diagram object.

  • full_res_im (numpy.ndarray, optional) – The full-size image where the gene expression mask should be plotted.

  • ROI_tuple (tuple, optional) – A tuple (left, bottom, width, height) representing the region of interest (ROI) where the gene expression mask should be displayed. If None, the entire img_mask will be plotted.

  • img_alpha (float, optional) – Alpha value (transparency) of the full_res_im if provided. Default is 1 (fully opaque).

  • figsize (tuple, optional) – Figure size in inches (width, height). Default is (5, 5).

  • dpi (int, optional) – Dots per inch for the figure. Default is 500.

  • show_cbar (bool, optional) – Whether to show the colorbar. Default is True.

  • cbar_loc (list, optional) – The location of the colorbar as [left, bottom, width, height]. Default is [1.04, 0.02, 0.05, 0.15].

  • return_fig (bool, optional) – If True, return the Figure object. Default is False.

  • show (bool, optional) – If True, display the plot. If False, return the Axes object without displaying the plot. Default is False.

  • **imshow_kwds (dict, optional) – Additional keyword arguments for customizing the imshow function, such as ‘cmap’, ‘vmin’, ‘vmax’, etc.

Returns:

If return_fig is False and show is False, the function returns the Axes object. If return_fig is True, the function returns the Figure object. If show is True, the function displays the plot and returns None.

Return type:

matplotlib.axes.Axes or matplotlib.figure.Figure, optional

Notes

This function plots the gene expression mask within a specified region of interest (ROI) or the entire img_mask if ROI_tuple is None. The function can overlay the gene expression mask on a full-size image (full_res_im) and/or a Voronoi diagram (vor) if provided.

The function allows customization of the colormap using the use_global_vmax and use_global_vmin parameters, which automatically set the maximum and minimum color values based on the global maximum and minimum values of the img_mask, respectively.

Examples

>>> import numpy as np
>>> # Assuming `img_mask` is a numpy array representing the gene expression mask.
>>> # Also, `vor` is a Voronoi diagram object, and `full_res_im` is a numpy array containing the full-size image.
>>> pl.single("Gene_X", img_mask, vor=vor, full_res_im=full_res_im, ROI_tuple=(10, 20, 30, 40))
>>> # Customizing the plot with optional arguments
>>> pl.single("Gene_Y", img_mask, show_cbar=False, cmap='viridis', use_global_vmax=False, figsize=(8, 6))