spac.visualization.histogram(adata, feature=None, annotation=None, layer=None, group_by=None, together=False, ax=None, x_log_scale=False, y_log_scale=False, **kwargs)[source]

Plot the histogram of cells based on a specific feature from adata.X or annotation from adata.obs.

Parameters:
  • adata (anndata.AnnData) – The AnnData object.

  • feature (str, optional) – Name of continuous feature from adata.X to plot its histogram.

  • annotation (str, optional) – Name of the annotation from adata.obs to plot its histogram.

  • layer (str, optional) – Name of the layer in adata.layers to plot its histogram.

  • group_by (str, default None) – Choose either to group the histogram by another column.

  • together (bool, default False) – If True, and if group_by != None, create one plot combining all groups. If False, create separate histograms for each group. The appearance of combined histograms can be controlled using the multiple and element parameters in **kwargs. To control how the histograms are normalized (e.g., to divide the histogram by the number of elements in every group), use the stat parameter in **kwargs. For example, set stat=”probability” to show the relative frequencies of each group.

  • ax (matplotlib.axes.Axes, optional) – An existing Axes object to draw the plot onto, optional.

  • x_log_scale (bool, default False) – If True, the data will be transformed using np.log1p before plotting, and the x-axis label will be adjusted accordingly.

  • y_log_scale (bool, default False) – If True, the y-axis will be set to log scale.

  • **kwargs

    Additional keyword arguments passed to seaborn histplot function. Key arguments include: - multiple: Determines how the subsets of data are displayed

    on the same axes. Options include:
    • ”layer”: Draws each subset on top of the other

      without adjustments.

    • ”dodge”: Dodges bars for each subset side by side.

    • ”stack”: Stacks bars for each subset on top of each other.

    • ”fill”: Adjusts bar heights to fill the axes.

    • element: Determines the visual representation of the bins.
      Options include:
      • ”bars”: Displays the typical bar-style histogram (default).

      • ”step”: Creates a step line plot without bars.

      • ”poly”: Creates a polygon where the bottom edge represents

        the x-axis and the top edge the histogram’s bins.

    • log_scale: Determines if the data should be plotted on

      a logarithmic scale.

    • stat: Determines the statistical transformation to use on the data
      for the histogram. Options include:
      • ”count”: Show the counts of observations in each bin.

      • ”frequency”: Show the number of observations divided by the bin width.

      • ”density”: Normalize such that the total area of the histogram

        equals 1.

      • ”probability”: Normalize such that each bar’s height reflects

        the probability of observing that bin.

    • bins: Specification of hist bins.

      Can be a number (indicating the number of bins) or a list (indicating bin edges). For example, bins=10 will create 10 bins, while bins=[0, 1, 2, 3] will create bins [0,1), [1,2), [2,3]. If not provided, the binning will be determined automatically.

Returns:

  • fig (matplotlib.figure.Figure) – The created figure for the plot.

  • axs (matplotlib.axes.Axes or list of Axes) – The Axes object(s) of the histogram plot(s). Returns a single Axes if only one plot is created, otherwise returns a list of Axes.