scanpy.pl.rank_genes_groups_matrixplot
- scanpy.pl.rank_genes_groups_matrixplot(adata, groups=None, n_genes=None, groupby=None, values_to_plot=None, var_names=None, gene_symbols=None, min_logfoldchange=None, key=None, show=None, save=None, return_fig=False, **kwds)
Plot ranking of genes using matrixplot plot (see
matrixplot()
)- Parameters:
- adata :
AnnData
Annotated data matrix.
- groups :
Union
[str
,Sequence
[str
],None
] (default:None
) The groups for which to show the gene ranking.
- n_genes :
Optional
[int
] (default:None
) Number of genes to show. This can be a negative number to show for example the down regulated genes. eg: num_genes=-10. Is ignored if
gene_names
is passed.- gene_symbols :
Optional
[str
] (default:None
) Column name in
.var
DataFrame that stores gene symbols. By defaultvar_names
refer to the index column of the.var
DataFrame. Setting this option allows alternative names to be used.- groupby :
Optional
[str
] (default:None
) The key of the observation grouping to consider. By default, the groupby is chosen from the rank genes groups parameter but other groupby options can be used. It is expected that groupby is a categorical. If groupby is not a categorical observation, it would be subdivided into
num_categories
(seedotplot()
).- min_logfoldchange :
Optional
[float
] (default:None
) Value to filter genes in groups if their logfoldchange is less than the min_logfoldchange
- key :
Optional
[str
] (default:None
) Key used to store the ranking results in
adata.uns
.- values_to_plot :
Optional
[Literal
['scores'
,'logfoldchanges'
,'pvals'
,'pvals_adj'
,'log10_pvals'
,'log10_pvals_adj'
]] (default:None
) Instead of the mean gene value, plot the values computed by
sc.rank_genes_groups
. The options are: [‘scores’, ‘logfoldchanges’, ‘pvals’, ‘pvals_adj’, ‘log10_pvals’, ‘log10_pvals_adj’]. When plotting logfoldchanges a divergent colormap is recommended. See examples below.- var_names :
Union
[Sequence
[str
],Mapping
[str
,Sequence
[str
]],None
] (default:None
) Genes to plot. Sometimes is useful to pass a specific list of var names (e.g. genes) to check their fold changes or p-values, instead of the top/bottom genes. The var_names could be a dictionary or a list as in
dotplot()
ormatrixplot()
. See examples below.- show :
Optional
[bool
] (default:None
) Show the plot, do not return axis.
- save :
Optional
[bool
] (default:None
) If
True
or astr
, save the figure. A string is appended to the default filename. Infer the filetype if ending on {'.pdf'
,'.png'
,'.svg'
}.- ax
A matplotlib axes object. Only works if plotting a single component.
- return_fig :
Optional
[bool
] (default:False
) Returns
MatrixPlot
object. Useful for fine-tuning the plot. Takes precedence overshow=False
.- **kwds
Are passed to
matrixplot()
.
- adata :
- Returns:
: If
return_fig
isTrue
, returns aMatrixPlot
object, else ifshow
is false, return axes dict
Examples
import scanpy as sc adata = sc.datasets.pbmc68k_reduced() sc.tl.rank_genes_groups(adata, 'bulk_labels', n_genes=adata.raw.shape[1])
Plot
logfoldchanges
instead of gene expression. In this case a diverging colormap likebwr
orseismic
works better. To center the colormap in zero, the minimum and maximum values to plot are set to -4 and 4 respectively. Also, only genes with a log fold change of 3 or more are shown.sc.pl.rank_genes_groups_matrixplot( adata, n_genes=4, values_to_plot="logfoldchanges", cmap='bwr', vmin=-4, vmax=4, min_logfoldchange=3, colorbar_title='log fold change', )
Also, the last genes can be plotted. This can be useful to identify genes that are lowly expressed in a group. For this
n_genes=-4
is usedsc.pl.rank_genes_groups_matrixplot( adata, n_genes=-4, values_to_plot="logfoldchanges", cmap='bwr', vmin=-4, vmax=4, min_logfoldchange=3, colorbar_title='log fold change', )
A list specific genes can be given to check their log fold change. If a dictionary, the dictionary keys will be added as labels in the plot.
var_names = {"T-cell": ['CD3D', 'CD3E', 'IL32'], 'B-cell': ['CD79A', 'CD79B', 'MS4A1'], 'myeloid': ['CST3', 'LYZ'] } sc.pl.rank_genes_groups_matrixplot( adata, var_names=var_names, values_to_plot="logfoldchanges", cmap='bwr', vmin=-4, vmax=4, min_logfoldchange=3, colorbar_title='log fold change', )