matrixplot#
API pages include interactive (HTML) plots that would possibly not render correctly on a mobile device.
- matrixplot(data: AnnData, keys: Sequence[str] | Mapping[str, Sequence[str]] | None = None, group_by: str | None = None, *, markers: bool | str = False, n_genes: int = 5, groups: Sequence[str] | None = None, mapping: FeatureSpec | None = None, geom: Literal['raster', 'tile'] = 'raster', scale_axis: Literal[0, 1] | None = None, dendrogram: bool = False, group_lines: bool = True, group_lines_color: str = 'white', group_lines_size: float = 0.6, dendrogram_color: str = 'black', dendrogram_size: float = 0.5, dendrogram_key: str | None = None, group_lines_kwargs: dict | None = None, dendrogram_kwargs: dict | None = None, key_labels: bool = True, key_labels_text_size: float = 1.0, key_labels_bracket_size: float = 0.6, key_labels_text_color: str = 'black', key_labels_bracket_color: str = 'black', key_labels_width: float = 0.6, value_column: str = 'value', variable_column: str = 'variable', color_low: str = '#0000ff', color_mid: str = '#ffffff', color_high: str = '#ff0000', mid_point: Literal['mean', 'median', 'mid'] | float = 'mid', axis: Literal[0, 1] | None = 0, observations_name: str = 'Barcode', variables_name: str = 'Variable', include_dimensions: bool | int = False, interactive: bool = False, **geom_kwargs) PlotSpec#
Matrix plot.
- Parameters:
data (
AnnData) – The single-cell data object.keys (
Sequence[str] | Mapping[str,Sequence[str]] | None, defaultNone) – Variable keys to include, placed on the x-axis. A mapping assigns keys to group labels (no key in more than one group). Must be None when markers is set.group_by (
str | None, defaultNone) – The key to group the data by. Inferred from a precomputed ranking when markers is set.markers (
bool | str, defaultFalse) – Derive keys from a precomputed ranking. Pass True to use the default ranking key, or a string to read a custom key (e.g. “rank_genes_groups_wilcoxon”).n_genes (
int, default5) – Number of top genes to take per group when markers is set.groups (
Sequence[str] | None, defaultNone) – Subset of groups to include when markers is set; None keeps all groups in their stored order.mapping (
FeatureSpec | None, defaultNone) – Aesthetic mappings for the plot, the result of aes().geom (
{'raster', 'tile'}, default'raster') – The geom to use. Use ‘raster’ for performance. Use ‘tile’ to enable tooltips.scale_axis (
{0, 1}| None, defaultNone) – Whether to standardize a dimension between 0 and 1. Uses min-max scaling; constant partitions are set to 0. If 0, standardize each variable (column). If 1, standardize each group (row).dendrogram (
bool, defaultFalse) – Whether to add a dendrogram for the group_by axis. Uses the precomputed dendrogram, computing one if not already present.group_lines (
bool, defaultTrue) – Whether to draw horizontal lines within the plot separating groups.group_lines_color (
str, default'white') – Color of the group separator lines.group_lines_size (
float, default0.6) – Size (thickness) of the group separator lines.dendrogram_color (
str, default'black') – Color of the dendrogram segments.dendrogram_size (
float, default0.5) – Size (thickness) of the dendrogram segments.dendrogram_key (
str | None, defaultNone) – Specific key holding the precomputed dendrogram. By default, dendrogram_{group_by} is used.group_lines_kwargs (
dict | None, defaultNone) – Additional parameters to pass to the group separator lines geom_segment.dendrogram_kwargs (
dict | None, defaultNone) – Additional parameters to pass to the dendrogram geom_segment.key_labels (
bool, defaultTrue) – Whether to draw bracket labels above the plot when keys is a mapping.key_labels_text_size (
float, default1.0) – Scale multiplier on the auto-computed bracket label text size.key_labels_bracket_size (
float, default0.6) – Size (thickness) of the bracket lines.key_labels_text_color (
str, default'black') – Color of the bracket label text.key_labels_bracket_color (
str, default'black') – Color of the bracket lines.key_labels_width (
float, default0.6) – Bracket width (in column units) for a singleton group. Multi-key groups extend key_labels_width / 2 past the first and last key on each side.value_column (
str, default'value') – Name for the value column after unpivoting.variable_column (
str, default'variable') – Name for the variable column after unpivoting.color_low (
str, default'#0000ff') – Color for low values in the gradient.color_mid (
str, default'#ffffff') – Color for mid values in the gradient.color_high (
str, default'#ff0000') – Color for high values in the gradient.mid_point (
{'mean', 'median', 'mid'}| float, default'mid') – Midpoint for the color gradient.axis (
{0,1}| None, default0) – Axis of the data, 0 for observations and 1 for variables.observations_name (
str, default'Barcode') – The name of the observations column.variables_name (
str, default'Variable') – Name for the variables index column.include_dimensions (
bool | int, defaultFalse) – Whether to include dimensions in the DataFrame. Providing an integer will limit the number of dimensions to given number.interactive (
bool, defaultFalse) – Whether to make the plot interactive.**geom_kwargs – Additional parameters for the heatmap geom layer.
- Returns:
PlotSpec– Matrix plot.
Notes
Equivalent to heatmap with aggregate=True.
Examples
Matrix plot of marker expression aggregated per cell type.
import scanpy as sc from lets_plot import * import cellestial as cl data = cl.datasets.pbmc3k(cache_directory="data") markers = ["C1QA", "PSAP", "CD79A", "CD79B", "CST3", "LYZ"] cl.matrixplot( data, group_by="cell_type_lvl1", keys=markers, dendrogram=True, )
Standardize per-variable so each marker spans 0-1 across groups.
cl.matrixplot( data, group_by="cell_type_lvl1", keys=markers, scale_axis=0, )
Plot the top genes from a precomputed ranking:
sc.tl.rank_genes_groups(data, groupby="cell_type_lvl1") cl.matrixplot(data, markers=True, n_genes=5)
WARNING: It seems you use rank_genes_groups on the raw count data. Please logarithmize your data before calling rank_genes_groups.