scanpy.pl.MatrixPlot.legend

scanpy.pl.MatrixPlot.legend#

MatrixPlot.legend(*, show=True, title='Expression\\nlevel in group', width=1.5)[source]#

Configure legend parameters

Parameters:
show bool | None (default: True)

Set to ‘False’ to hide the default plot of the legend. This sets the legend width to zero which will result in a wider main plot.

title str | None (default: 'Expression\\nlevel in group')

Legend title. Appears on top of the color bar. Use ‘\n’ to add line breaks.

width float | None (default: 1.5)

Width of the legend. The unit is the same as in matplotlib (inches)

Return type:

Self

Returns:

Returns self for method chaining.

Examples

Set legend title:

>>> import scanpy as sc
>>> adata = sc.datasets.pbmc68k_reduced()
>>> markers = {'T-cell': 'CD3D', 'B-cell': 'CD79A', 'myeloid': 'CST3'}
>>> dp = sc.pl._baseplot_class.BasePlot(adata, markers, groupby='bulk_labels') \
...     .legend(title='log(UMI counts + 1)')
>>> dp.color_legend_title
'log(UMI counts + 1)'