thor.pl.multiple

thor.pl.multiple(vars_list, img_masks_list, ax=None, vor=None, palette='tab20', full_res_im=None, ROI_tuple=None, img_alpha=1, figsize=(5, 5), dpi=150, show_legend=True, legend_loc='upper left', show_cbar=False, return_fig=False, show=False, **imshow_kwds)[source]

Color the cells or nuclei with multiple variables.

Parameters:
  • vars_list (list) – List of variable names to color the cells or nuclei.

  • img_masks_list (list of numpy.ndarray) – List of image masks filled with the variable values. Each mask should have the same size as full_res_im.

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

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

  • palette (str or list or tuple or numpy.ndarray, optional) – The color palette to use for coloring variables. Can be a valid matplotlib colormap name, or a list/tuple/array of colors.

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

  • ROI_tuple (tuple, optional) – A tuple (left, bottom, width, height) representing the region of interest (ROI) where the gene expression masks should be displayed.

  • 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 150.

  • show_legend (bool, optional) – Whether to show the legend indicating variables. Default is True.

  • legend_loc (str, optional) – Location for the legend. Default is ‘upper left’.

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

  • 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 multiple gene expression masks within a specified region of interest (ROI) or the entire img_masks_list if ROI_tuple is None. Each variable’s mask is color-coded using the provided palette.

The function supports showing either a legend indicating the variables (show_legend=True) or a single colorbar (show_cbar=True) for the entire plot. Both options cannot be selected simultaneously.

Examples

>>> import numpy as np
>>> # Assuming `img_masks_list` is a list of numpy arrays representing gene expression masks.
>>> # Also, `vor` is a Voronoi diagram object, and `full_res_im` is a numpy array containing the full-size image.
>>> pl.multiple(["Gene_X", "Gene_Y"], img_masks_list, vor=vor, full_res_im=full_res_im, ROI_tuple=(10, 20, 30, 40))
>>> # Customizing the plot with optional arguments
>>> pl.multiple(["Gene_A", "Gene_B"], img_masks_list, show_legend=False, palette=['red', 'blue'], use_global_vmax=False, figsize=(8, 6))