spateo.plotting.static.dotplot
==============================
.. py:module:: spateo.plotting.static.dotplot
.. autoapi-nested-parse::
Dotplot class adapted from https://github.com/scverse/scanpy with modifications for suitability to cell-cell
communication and interaction analyses
Development notes: some of the methods mention dendrograms/other extra plots and there is currently no capability to
generate those- coming in future update...additions that will have to be made: functions for plot_dendrogram,
plot_totals, additional if condition in make_figure()...
Classes
-------
.. autoapisummary::
spateo.plotting.static.dotplot.Dotplot
spateo.plotting.static.dotplot.CCDotplot
Functions
---------
.. autoapisummary::
spateo.plotting.static.dotplot.adata_to_frame
spateo.plotting.static.dotplot.make_grid_spec
spateo.plotting.static.dotplot.dotplot
Module Contents
---------------
.. py:function:: adata_to_frame(adata: anndata.AnnData, var_names: Sequence[str], cat_key: Union[str, Sequence[str]], num_categories: int = 7, layer: Union[None, str] = None, gene_symbols_key: Union[None, str] = None)
For the purposes of dot plotting, converts the information given in AnnData object to a dataframe in which the
row names are categories defined by groups and column names correspond to variable names.
:param adata: class `anndata.AnnData`
:param var_names: Should be a subset of adata.var_names
:param cat_key: The key(s) in .obs of the grouping to consider. Should be a categorical observation; if not,
will be subdivided into 'num_categories'.
:param num_categories: Only used if groupby observation is not categorical. This value determines the number of groups into
which the groupby observation should be subdivided.
:param layer: Key in .layers specifying layer to use. If not given, will use .X.
:param gene_symbols_key: Key in .var containing gene symbols
.. py:function:: make_grid_spec(ax_or_figsize: Union[Tuple[int, int], matplotlib.axes.Axes], nrows: int, ncols: int, wspace: Optional[float] = None, hspace: Optional[float] = None, width_ratios: Optional[Sequence[float]] = None, height_ratios: Optional[Sequence[float]] = None) -> Tuple[matplotlib.figure.Figure, matplotlib.gridspec.GridSpecBase]
Initialize grid layout to place subplots within a figure environment
:param ax_or_figsize: Either already-existing ax object or the width and height to create a figure window
:param nrows: Number of rows in the grid
:param ncols: Number of columns in the grid
:param wspace: The amount of width reserved for space between subplots, expressed as a fraction of the average axis width
:param hspace: The amount of height reserved for space between subplots, expressed as a fraction of the average axis height
:param width_ratios: Defines the relative widths of the columns. Each column gets a relative width of width_ratios[i] / sum(
width_ratios). If not given, all columns will have the same width.
:param height_ratios: Defines the relative heights of the rows. Each row gets a relative width of height_ratios[i] / sum(
height_ratios). If not given, all columns will have the same width.
:returns: Instantiated Figure object
gs: Instantiated gridspec object
:rtype: fig
.. py:class:: Dotplot(adata: anndata.AnnData, var_names: Sequence[str], cat_key: Union[str, Sequence[str]], num_categories: int = 7, prescale_adata: bool = False, categories_order: Union[None, Sequence[str]] = None, title: Union[None, str] = None, figsize: Union[None, Tuple[float, float]] = None, gene_symbols_key: Union[None, str] = None, var_group_positions: Union[None, Sequence[Tuple[int, int]]] = None, var_group_labels: Union[None, Sequence[str]] = None, var_group_rotation: Union[None, float] = None, layer: Union[None, str] = None, expression_cutoff: float = 0.0, mean_only_expressed: bool = False, standard_scale: Literal['var', 'group'] = None, dot_color_df: Optional[pandas.DataFrame] = None, dot_size_df: Optional[pandas.DataFrame] = None, ax: Union[None, matplotlib.axes.Axes] = None, vmin: Union[None, float] = None, vmax: Union[None, float] = None, vcenter: Union[None, float] = None, norm: Optional[matplotlib.colors.Normalize] = None, **kwargs)
Simultaneous visualization of two variates that are encoded by the dot size and the dot color. Size usually
represents the fraction of samples that have non-zero values, and color usually represents the magnitude of the
value.
:param adata: class `anndata.AnnData`
:param var_names: Should be a subset of adata.var_names
:param cat_key: The key(s) in .obs of the grouping to consider. Should be a categorical observation; if not,
will be subdivided into 'num_categories'.
:param num_categories: Only used if groupby observation is not categorical. This value determines the number of
groups into which the groupby observation should be subdivided.
:param categories_order: Sets order of categories given by 'cat_key' along the plotting axis
:param title: Sets title for figure window
:param figsize: The width and height of a figure
:param gene_symbols_key: Key in .var containing gene symbols
:param var_group_positions: Each item in the list should contain the start and end position that the bracket
should cover. Eg. [(0, 4), (5, 8)] means that there are two brackets, one for the var_names in positions 0-4
and other for positions 5-8.
:param var_group_labels: List of group labels for the variable names (e.g. can group var_names in positions 0-4
as being "group A")
:param var_group_rotation: Rotation in degrees of the variable name labels. If not given, small labels (<4
characters) are not rotated, but otherwise labels are rotated 90 degrees.
:param layer: Key in .layers specifying layer to use. If not given, will use .X.
:param expression_cutoff: Used for binarizing feature expression- feature is considered to be expressed only if
the expression value is greater than this threshold
:param mean_only_expressed: If True, gene expression is averaged only over the cells expressing the given features
:param standard_scale: Whether or not to standardize that dimension between 0 and 1, meaning for each variable or
group, subtract the minimum and divide each by its maximum. 'val' or 'group' is used to specify whether this
should be done over variables or groups.
:param dot_color_df: Pre-prepared dataframe with features as indices, categories as columns, and indices
corresponding to color intensities
:param dot_size_df: Pre-prepared dataframe with features as indices, categories as columns, and indices
corresponding to dot sizes
:param ax: Can be used to provide pre-existing plotting axis
:param vmin: The data value that defines 0.0 in the normalization. Defaults to the min value of the dataset.
:param vmax: The data value that defines 1.0 in the normalization. Defaults to the the max value of the dataset.
:param vcenter: The data value that defines 0.5 in the normalization
:param norm: Optional already-initialized normalizing object that scales data, typically into the interval [0, 1],
for the purposes of mapping to color intensities for plotting. Do not pass both 'norm' and
'vmin'/'vmax', etc.
:param \*\*kwargs: Additional arguments passed to `matplotlib.pyplot.scatter()`
.. py:attribute:: default_colormap
:value: 'winter'
.. py:attribute:: default_color_on
:value: 'dot'
.. py:attribute:: default_dot_max
:value: None
.. py:attribute:: default_dot_min
:value: None
.. py:attribute:: default_smallest_dot
:value: 0.0
.. py:attribute:: default_largest_dot
:value: 200.0
.. py:attribute:: default_dot_edgecolor
:value: 'black'
.. py:attribute:: default_dot_edgelw
:value: 0.2
.. py:attribute:: default_size_exponent
:value: 1.5
.. py:attribute:: default_size_legend_title
:value: Multiline-String
.. raw:: html
Show Value
.. code-block:: python
"""Fraction of cells
in group (%)"""
.. raw:: html
.. py:attribute:: default_color_legend_title
:value: Multiline-String
.. raw:: html
Show Value
.. code-block:: python
"""Mean expression
in group"""
.. raw:: html
.. py:attribute:: default_base
:value: 10
.. py:attribute:: default_num_colorbar_ticks
:value: 5
.. py:attribute:: default_num_size_legend_dots
:value: 5
.. py:attribute:: default_legends_width
:value: 1.5
.. py:attribute:: default_plot_x_padding
:value: 0.8
.. py:attribute:: default_plot_y_padding
:value: 1.0
.. py:attribute:: default_category_height
:value: 0.35
.. py:attribute:: default_category_width
:value: 0.37
.. py:attribute:: min_figure_height
:value: 2.5
.. py:attribute:: default_wspace
:value: 0
.. py:attribute:: logger
.. py:attribute:: adata
.. py:attribute:: cat_key
.. py:attribute:: kwargs
.. py:attribute:: var_names
.. py:attribute:: var_group_labels
:value: None
.. py:attribute:: var_group_positions
:value: None
.. py:attribute:: var_group_rotation
:value: None
.. py:attribute:: has_var_groups
:value: True
.. py:attribute:: fig_title
:value: None
.. py:attribute:: max_num_categories
:value: 100
.. py:attribute:: dot_color_df
.. py:attribute:: dot_size_df
:value: None
.. py:attribute:: cmap
:value: 'winter'
.. py:attribute:: dot_max
:value: None
.. py:attribute:: dot_min
:value: None
.. py:attribute:: smallest_dot
:value: 0.0
.. py:attribute:: largest_dot
:value: 200.0
.. py:attribute:: color_on
:value: 'dot'
.. py:attribute:: size_exponent
:value: 1.5
.. py:attribute:: grid
:value: False
.. py:attribute:: plot_x_padding
:value: 0.8
.. py:attribute:: plot_y_padding
:value: 1.0
.. py:attribute:: dot_edge_color
:value: 'black'
.. py:attribute:: dot_edge_lw
:value: 0.2
.. py:attribute:: color_legend_title
:value: Multiline-String
.. raw:: html
Show Value
.. code-block:: python
"""Mean expression
in group"""
.. raw:: html
.. py:attribute:: size_title
:value: Multiline-String
.. raw:: html
Show Value
.. code-block:: python
"""Fraction of cells
in group (%)"""
.. raw:: html
.. py:attribute:: num_colorbar_ticks
:value: 5
.. py:attribute:: num_size_legend_dots
:value: 5
.. py:attribute:: base
:value: 10
.. py:attribute:: legends_width
:value: 1.5
.. py:attribute:: show_size_legend
:value: True
.. py:attribute:: show_colorbar
:value: True
.. py:attribute:: wspace
:value: 0
.. py:attribute:: vboundnorm
.. py:attribute:: are_axes_swapped
:value: False
.. py:attribute:: categories_order
:value: None
.. py:attribute:: var_names_idx_order
:value: None
.. py:attribute:: group_extra_size
:value: 0
.. py:attribute:: plot_group_extra
:value: None
.. py:attribute:: fig
:value: None
.. py:attribute:: ax_dict
:value: None
.. py:attribute:: ax
:value: None
.. py:method:: swap_axes()
Modifies variables to flip x- and y-axes of dotplot.
By default, the x axis contains 'var_names' (e.g. genes) and the y axis the groupby categories. By setting
'swap_axes' the x-axis becomes the categories and the y-axis becomes the variable names.
.. py:method:: add_dendrogram(show: bool = True, dendrogram_key: Union[None, str] = None, size: float = 0.8)
Show dendrogram based on the hierarchical clustering between the `cat_key` categories. Categories are
reordered to match the dendrogram order.
The dendrogram information is computed using :func:`utils.dendrogram` within Spateo.
If `utils.dendrogram` has not been called previously the function is called with default parameters here.
The dendrogram is by default shown on the right side of the plot or on top if the axes are swapped.
:param show: Boolean to turn on (True) or off (False) 'add_dendrogram'
:param dendrogram_key: Needed if :func `utils.dendrogram` saved the dendrogram using a key different than the
default name.
:param size: Size of the dendrogram. Corresponds to width when dendrogram shown on the right of the plot,
:param or height when shown on top. The unit is the same as in matplotlib:
:type or height when shown on top. The unit is the same as in matplotlib: inches
.. py:method:: style(cmap: str = default_colormap, color_on: Optional[Literal['dot', 'square']] = default_color_on, dot_max: Optional[float] = default_dot_max, dot_min: Optional[float] = default_dot_min, smallest_dot: Optional[float] = default_smallest_dot, largest_dot: Optional[float] = default_largest_dot, dot_edge_color: Optional[float] = default_dot_edgecolor, dot_edge_lw: Optional[float] = default_dot_edgelw, size_exponent: Optional[float] = default_size_exponent, grid: Optional[float] = False, x_padding: Optional[float] = default_plot_x_padding, y_padding: Optional[float] = default_plot_y_padding)
Modifies visual aspects of the dot plot
Args:
cmap: Name of Matplotlib color map to use
color_on: Options are 'dot' or 'square'. By default the colormap is applied to the color of the dot,
but 'square' changes this to be applied to a square region behind the dot, in which case the dot becomes
transparent with only the edge of the dot shown.
dot_max: If none, the maximum dot size is set to the maximum fraction value found (e.g. 0.6). If given,
the value should be a number between 0 and 1. All fractions larger than dot_max are clipped to this value.
dot_min: If none, the minimum dot size is set to 0. If given, the value should be a number between 0 and 1.
All fractions smaller than dot_min are clipped to this value.
smallest_dot: If none, the smallest dot has size 0. All expression fractions with `dot_min` are plotted with this size.
largest_dot: If none, the largest dot has size 200. All expression fractions with `dot_max` are plotted with this size.
dot_edge_color: Only used if 'color_on' is 'square'. Sets dot edge color
dot_edge_lw: Only used if 'color_on' is 'square'. Sets dot edge line width
size_exponent: Dot size is computed as:
fraction ** size exponent
and is afterwards scaled to match the 'smallest_dot' and 'largest_dot' size parameters.
Using a different size exponent changes the relative sizes of the dots to each other.
grid: Set to true to show grid lines. By default grid lines are not shown. Further configuration of the grid
lines can be achieved directly on the returned ax.
x_padding: Space between the plot left/right borders and the dots center. A unit is the distance between the x
ticks. Only applied when 'color_on' = 'dot'
y_padding: Space between the plot top/bottom borders and the dots center. A unit is the distance between the x
ticks. Only applied when 'color_on' = 'dot'
:returns: self (instance of class DotPlot)
.. rubric:: Example
Creating a modified dot plot (w/ a loaded AnnData object given name 'adata'):
markers = ['C1QA', 'PSAP', 'CD79A', 'CD79B', 'CST3', 'LYZ']
st.pl.DotPlot(adata, var_names=markers, cat_key='Celltype').style(cmap='RdBu_r', color_on='square').show()
.. py:method:: legend(show: bool = True, show_size_legend: bool = True, show_colorbar: bool = True, size_title: Optional[str] = default_size_legend_title, colorbar_title: Optional[str] = default_color_legend_title, base: Optional[int] = default_base, num_colorbar_ticks: Optional[int] = default_num_colorbar_ticks, num_size_legend_dots: Optional[int] = default_num_size_legend_dots, width: Optional[float] = default_legends_width)
Configures colorbar and other legends for dotplot
:param show: Set to `False` to hide the default plot of the legends. This sets the legend width to zero,
which will result in a wider main plot.
:param show_size_legend: Set to `False` to hide the dot size legend
:param show_colorbar: Set to `False` to hide the colorbar legend
:param size_title: Title for the dot size legend. Use '\n' to add line breaks. Will be shown at the top of
the dot size legend box
:param colorbar_title: Title for the color bar. Use '\n' to add line breaks. Will be shown at the top of the
color bar.
:param base: To determine the size of each "benchmark" dot in the size legend, will use a logscale; this parameter
sets the base of that scale.
:param num_colorbar_ticks: Number of ticks for the colorbar
:param num_size_legend_dots: Number of "benchmark" dots to include in the dot size legend
:param width: Width of the legends area. The unit is the same as in matplotlib (inches)
:returns: self (instance of class DotPlot)
.. rubric:: Example
Setting the colorbar title (w/ a loaded AnnData object given name 'adata'):
markers = {{'T-cell': 'CD3D', 'B-cell': 'CD79A', 'myeloid': 'CST3'}}
dp = st.pl.DotPlot(adata, markers, groupby='Celltype')
dp.legend(colorbar_title='log(UMI counts + 1)').show()
.. py:method:: get_axes()
.. py:method:: _plot_size_legend(size_legend_ax: matplotlib.axes.Axes)
Given axis object, generates dot size legend and displays on plot
For the dot size "benchmarks" on the legend, adjust the difference in size between consecutive benchmarks
based on how different 'self.dot_max' and 'self.dot_min' are.
.. py:method:: _plot_colorbar(color_legend_ax: matplotlib.axes.Axes, normalize: Union[None, matplotlib.colors.Normalize] = None)
Given axis object, plots a horizontal colorbar
:param color_legend_ax: `mpl.axes.Axes` object
Matplotlib axis object to plot onto
:param normalize: `mpl.colors.Normalize` object
The normalizing object that scales data, typically into the interval [0, 1], for the purposes of
mapping to color intensities for plotting. If None, norm defaults to a colors.Normalize object and
automatically scales based on min/max values in the data.
.. py:method:: _plot_legend(legend_ax: matplotlib.axes.Axes, return_ax_dict: dict, normalize: Union[None, matplotlib.colors.Normalize] = None)
Organizes the size legend and color legend.
The structure for the legends is:
First row: Empty space of variable size to control the size of the other rows
Second row: Dot size legend
Third row: Spacer to prevent titles/labels of the color and dot size legends overlapping
Fourth row: Colorbar
:param legend_ax: mpl.axes.Axes
Matplotlib axis object to plot onto
:param return_ax_dict:
.. py:method:: _mainplot(ax: matplotlib.axes.Axes)
.. py:method:: _dotplot(dot_size: pandas.DataFrame, dot_color: pandas.DataFrame, dot_ax: matplotlib.axes.Axes, cmap: str = 'Reds', color_on: str = 'dot', y_label: Union[None, str] = None, dot_max: Union[None, float] = None, dot_min: Union[None, float] = None, standard_scale: Union[None, Literal['var', 'group']] = None, smallest_dot: float = 0.0, largest_dot: float = 200, size_exponent: float = 2, edge_color: Union[None, str] = None, edge_lw: Union[None, float] = None, grid: bool = False, x_padding: float = 0.8, y_padding: float = 1.0, vmin: Union[None, float] = None, vmax: Union[None, float] = None, vcenter: Union[None, float] = None, norm: Union[None, matplotlib.colors.Normalize] = None, **kwargs)
:staticmethod:
Generate a dotplot given the axis object and two dataframes containing the dot size and dot color. The
indices and columns of the dataframes are used to label the resultant image.
The dots are plotted using :func:`matplotlib.pyplot.scatter()`. Thus, additional
arguments can be passed.
:param dot_size: pd.DataFrame
Data frame containing the dot_size.
:param dot_color: pd.DataFrame
Data frame containing the dot_color, should have the same shape, columns and indices as dot_size.
:param dot_ax: matplotlib Axes object
Axis to plot figure onto
:param cmap: str, default 'Reds'
String denoting matplotlib color map
:param color_on: str, default 'dot'
Options: 'dot' or 'square'. By default the colormap is applied to the color of the dot. Optionally,
the colormap can be applied to an square behind the dot, in which case the dot is transparent and only
the edge is shown.
:param y_label: optional str
Label for y-axis
:param dot_max: optional float
If none, the maximum dot size is set to the maximum fraction value found (e.g. 0.6). If given,
the value should be a number between 0 and 1. All fractions larger than dot_max are clipped to this value.
:param dot_min: optional float
If none, the minimum dot size is set to 0. If given, the value should be a number between 0 and 1.
All fractions smaller than dot_min are clipped to this value.
:param standard_scale: 'None', 'val', or 'group'
Whether or not to standardize that dimension between 0 and 1, meaning for each variable or group,
subtract the minimum and divide each by its maximum. 'val' or 'group' is used to specify whether this
should be done over variables or groups.
:param smallest_dot: optional float
If none, the smallest dot has size 0. All expression fractions with `dot_min` are plotted with this size.
:param largest_dot: optional float
If none, the largest dot has size 200. All expression fractions with `dot_max` are plotted with this size.
:param size_exponent: float, default 1.5
Dot size is computed as:
fraction ** size exponent
and is afterwards scaled to match the 'smallest_dot' and 'largest_dot' size parameters.
Using a different size exponent changes the relative sizes of the dots to each other.
:param edge_color: str, default 'black'
Only used if 'color_on' is 'square'. Sets dot edge color
:param edge_lw: float, default 0.2
Only used if 'color_on' is 'square'. Sets dot edge line width
:param grid: bool, default False
Set to true to show grid lines. By default grid lines are not shown. Further configuration of the grid
lines can be achieved directly on the returned ax.
:param x_padding: float, default 0.8
Space between the plot left/right borders and the dots center. A unit is the distance between the x
ticks. Only applied when 'color_on' = 'dot'
:param y_padding: float, default 1.0
Space between the plot top/bottom borders and the dots center. A unit is the distance between the x
ticks. Only applied when 'color_on' = 'dot'
:param vmin: optional float
The data value that defines 0.0 in the normalization. Defaults to the min value of the dataset.
:param vmax: optional float
The data value that defines 1.0 in the normalization. Defaults to the the max value of the dataset.
:param vcenter: optional float
The data value that defines 0.5 in the normalization
:param norm: optional `matplotlib.colors.Normalize` object
Optional already-initialized normalizing object that scales data, typically into the interval [0, 1],
for the purposes of mapping to color intensities for plotting. Do not pass both 'norm' and
'vmin'/'vmax', etc.
:param \*\*kwargs: Additional arguments passed to `matplotlib.pyplot.scatter`
:returns:
`matplotlib.colors.Normalize` object
The normalizing object that scales data, typically into the interval [0, 1], for the purposes of
mapping to color intensities for plotting.
dot_min : float
The minimum dot size represented on the plot, given as a fration of the maximum value in the data
dot_max : float
The maximum dot size represented on the plot, given as a fraction of the maximum value in the data
:rtype: normalize
.. py:method:: reorder_categories_after_dendrogram(dendrogram_key)
Reorders categorical observations along plot axis based on dendrogram results.
The function checks if a dendrogram has already been precomputed. If not, `utils.dendrogram` is run with
default parameters.
The results found in `.uns[dendrogram_key]` are used to reorder `var_group_labels` and `var_group_positions`.
.. py:method:: _plot_var_groups_brackets(gene_groups_ax: matplotlib.axes.Axes, group_positions: Iterable[Tuple[int, int]], group_labels: Sequence[str], left_adjustment: float = -0.3, right_adjustment: float = 0.3, rotation: Optional[float] = None, orientation: Literal['top', 'right'] = 'top')
:staticmethod:
Draws brackets that represent groups of features on the given axis.
The 'gene_groups_ax' Axes object should share the x-axis/y-axis (depending on the axis along which the
features are plotted) with the main plot axis. For example, in instantiation:
gene_groups_ax = fig.add_subplot(axs[0,0], sharex=dot_ax)
:param gene_groups_ax: `matplotlib.axes.Axes` object
Axis to plot on, should correspond to the axis of the main plot on which the feature names/feature
ticks are drawn
:param group_positions: list of tuples of form (int, int)
Each item in the list, should contain the start and end position that the bracket should cover.
Eg. [(0, 4), (5, 8)] means that there are two brackets, one for the var_names (eg genes) in
positions 0-4 and the second for positions 5-8.
:param group_labels: list of str
List of labels for the feature groups
:param left_adjustment: float, default -0.3
Adjustment to plot the bracket start slightly before or after the first feature position.
If the value is negative the start is moved before.
:param right_adjustment: float, default 0.3
Adjustment to plot the bracket end slightly before or after the first feature position.
If the value is negative the end is moved before, if positive the end is moved after.
:param rotation: optional float
In degrees, angle of rotation for the labels. If not given, small labels (<4 characters) are not
rotated, otherwise, they are rotated 90 degrees
:param orientation: str
Options: 'top' or 'right' to set the location of the brackets
.. py:method:: _update_var_groups()
Checks if var_names is a dict. Is this is the cases, then set the
correct values for var_group_labels and var_group_positions
Updates var_names, var_group_labels, var_group_positions
.. py:method:: make_figure()
Renders the image, but does not call :func:`matplotlib.pyplot.show`.
.. py:class:: CCDotplot(minn: float, delta: float, alpha: float, *args, **kwargs)
Bases: :py:obj:`Dotplot`
Because of the often much smaller values dealt with in cell-cell communication inference, this class creates a
modified legend.
:param delta: optional float
Distance between the largest value to consider and the smallest value to consider (see 'minn'
parameter below)
:param minn: optional float
For the dot size legend, sets the value corresponding to the smallest dot on the legend
:param alpha: optional float
Significance threshold. If given, all elements w/ p-values <= 'alpha' will be marked by rings instead of
dots.
:param \*args: Positional arguments to initialize :class `Dotplot`
:param \*\*kwargs: Keyword arguments to initialize :class `Dotplot`
.. py:attribute:: base
:value: 10
.. py:attribute:: default_largest_dot
:value: 50.0
.. py:attribute:: delta
.. py:attribute:: minn
.. py:attribute:: alpha
.. py:attribute:: largest_dot
:value: 50.0
.. py:method:: _plot_size_legend(size_legend_ax: matplotlib.axes.Axes)
Given axis object, generates dot size legend and displays on plot
Overwrites the default :func `plot_size_legend` for :class `Dotplot`
.. py:function:: dotplot(adata: anndata.AnnData, var_names: Sequence[str], cat_key: Union[str, Sequence[str]], num_categories: int = 7, cell_cell_dp: bool = False, delta: Union[None, float] = None, minn: Union[None, float] = None, alpha: Union[None, float] = None, prescale_adata: bool = False, expression_cutoff: float = 0.0, mean_only_expressed: bool = False, cmap: str = 'Reds', dot_max: float = Dotplot.default_dot_max, dot_min: float = Dotplot.default_dot_min, standard_scale: Literal['var', 'group'] = None, smallest_dot: float = Dotplot.default_smallest_dot, largest_dot: float = Dotplot.default_largest_dot, title: str = None, colorbar_title: str = Dotplot.default_color_legend_title, size_title: str = Dotplot.default_size_legend_title, figsize: Union[None, Tuple[float, float]] = None, dendrogram: Union[bool, str] = False, gene_symbols_key: Union[None, str] = None, var_group_positions: Union[None, Sequence[Tuple[int, int]]] = None, var_group_labels: Union[None, Sequence[str]] = None, var_group_rotation: Union[None, float] = None, layer: Union[None, str] = None, swap_axes: bool = False, dot_color_df: Union[None, pandas.DataFrame] = None, save_show_or_return: Literal['save', 'show', 'return', 'both', 'all'] = 'save', save_kwargs: dict = {}, ax: Union[None, matplotlib.axes.Axes] = None, vmin: Union[None, float] = None, vmax: Union[None, float] = None, vcenter: Union[None, float] = None, norm: Union[None, matplotlib.colors.Normalize] = None, **kwargs)
Makes a dot plot of the expression values of `var_names`. For each var_name and each `groupby` category a dot
is plotted.
Each dot represents two values: mean expression within each category (visualized by color) and fraction of cells
expressing the `var_name` in the category (visualized by the size of the dot). If `groupby` is not given,
the dotplot assumes that all data belongs to a single category.
:param adata: object of class `anndata.AnnData`
:param var_names: Should be a subset of adata.var_names
:param cat_key: The key(s) in .obs of the grouping to consider. Should be a categorical observation; if not,
will be subdivided into 'num_categories'.
:param num_categories: Only used if groupby observation is not categorical. This value determines the number of
groups into which the groupby observation should be subdivided.
:param cell_cell_dp: Set True to initialize specialized cell-cell dotplot instead of gene expression dotplot
:param delta: Only used if 'cell_cell_dp' is True- distance between the largest value to consider and the smallest
value to consider (see 'minn' parameter below)
:param minn: Only used if 'cell_cell_dp' is True- for the dot size legend, sets the value corresponding to the
smallest dot on the legend
:param alpha: Only used if 'cell_cell_dp' is True- significance threshold. If given, all elements w/ p-values <=
'alpha' will be marked by rings instead of dots.
:param prescale_adata: Set True to indicate that AnnData object should be scaled- if so, will use 'delta' and
'minn' to do so. If False, will proceed as though adata has already been processed as needed.
:param expression_cutoff: Used for binarizing feature expression- feature is considered to be expressed only if
the expression value is greater than this threshold
:param mean_only_expressed: If True, gene expression is averaged only over the cells expressing the given features
:param cmap: Name of Matplotlib color map to use
:param dot_max: If none, the maximum dot size is set to the maximum fraction value found (e.g. 0.6). If given,
the value should be a number between 0 and 1. All fractions larger than dot_max are clipped to this value.
:param dot_min: If none, the minimum dot size is set to 0. If given, the value should be a number between 0 and 1.
All fractions smaller than dot_min are clipped to this value.
:param standard_scale: Whether or not to standardize that dimension between 0 and 1, meaning for each variable or
group, subtract the minimum and divide each by its maximum. 'val' or 'group' is used to specify whether this
should be done over variables or groups.
:param smallest_dot: If None, the smallest dot has size 0. All expression fractions with `dot_min` are plotted with
this size.
:param largest_dot: If None, the largest dot has size 200. All expression fractions with `dot_max` are plotted with
this size.
:param title: Title for the entire plot
:param colorbar_title: Title for the color legend. If None will use generic default title
:param size_title: Title for the dot size legend. If None will use generic default title
:param figsize: Sets width and height of figure window
:param dendrogram: If True, adds dendrogram to plot. Will do the same thing if string is given here,
but will recompute dendrogram and save using this argument to set key in .uns.
:param gene_symbols_key: Key in .var containing gene symbols
:param var_group_positions: Each item in the list should contain the start and end position that the bracket
should cover. Eg. [(0, 4), (5, 8)] means that there are two brackets, one for the var_names in positions
0-4 and other for positions 5-8
:param var_group_labels: List of group labels for the variable names (e.g. can group var_names in positions 0-4 as
being "group A")
:param var_group_rotation: Rotation in degrees of the variable name labels. If not given, small labels (<4
characters) are not rotated, but otherwise labels are rotated 90 degrees.
:param layer: Key in .layers specifying layer to use. If not given, will use .X.
:param swap_axes: Set True to switch what is plotted on the x- and y-axes
:param dot_color_df: Pre-prepared dataframe with features as indices, categories as columns, and indices
corresponding to color intensities
:param save_show_or_return: Options: "save", "show", "return", "both", "all"
- "both" for save and show
:param save_kwargs: A dictionary that will passed to the save_fig function. By default it is an empty dictionary
and the save_fig function will use the {"path": None, "prefix": 'scatter', "dpi": None, "ext": 'pdf',
"transparent": True, "close": True, "verbose": True} as its parameters. But to change any of these
parameters, this dictionary can be used to do so.
:param ax: Pre-initialized axis object to plot on
:param vmin: The data value that defines 0.0 in the normalization. Defaults to the min value of the dataset.
:param vmax: The data value that defines 1.0 in the normalization. Defaults to the the max value of the dataset.
:param vcenter: The data value that defines 0.5 in the normalization
:param norm: Optional already-initialized normalizing object that scales data, typically into the interval [0, 1],
for the purposes of mapping to color intensities for plotting. Do not pass both 'norm' and
'vmin'/'vmax', etc.
:param kwargs: Additional keyword arguments passed to :func:`matplotlib.pyplot.scatter`
:returns: Instantiated Figure object- only if 'return' is True
axes: Instantiated Axes object- only if 'return' is True
:rtype: fig