Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion scanpy/plotting/_anndata.py
Original file line number Diff line number Diff line change
Expand Up @@ -1573,7 +1573,9 @@ def dotplot(adata, var_names, groupby=None, use_raw=None, log=False, num_categor
@doc_params(show_save_ax=doc_show_save_ax, common_plot_args=doc_common_plot_args)
def matrixplot(adata, var_names, groupby=None, use_raw=None, log=False, num_categories=7,
figsize=None, dendrogram=False, gene_symbols=None, var_group_positions=None, var_group_labels=None,
var_group_rotation=None, layer=None, swap_axes=False, show=None, save=None, **kwds):
var_group_rotation=None, layer=None, standard_scale=None, swap_axes=False, show=None,
save=None, **kwds):

"""\
Creates a heatmap of the mean expression values per cluster of each var_names
If groupby is not given, the matrixplot assumes that all data belongs to a single
Expand All @@ -1582,6 +1584,9 @@ def matrixplot(adata, var_names, groupby=None, use_raw=None, log=False, num_cate
Parameters
----------
{common_plot_args}
standard_scale : {{'var', 'group'}}, optional (default: None)
Whether or not to standardize that dimension, meaning for each variable or group,
subtract the minimum and divide each by its maximum.
{show_save_ax}
**kwds : keyword arguments
Are passed to `matplotlib.pyplot.pcolor`.
Expand Down Expand Up @@ -1626,6 +1631,17 @@ def matrixplot(adata, var_names, groupby=None, use_raw=None, log=False, num_cate

mean_obs = obs_tidy.groupby(level=0).mean()

if standard_scale == 'group':
mean_obs = mean_obs.sub(mean_obs.min(1), axis=0)
mean_obs = mean_obs.div(mean_obs.max(1), axis=0)
elif standard_scale == 'var':
mean_obs -= mean_obs.min(0)
mean_obs /= mean_obs.max(0)
elif standard_scale is None:
pass
else:
logg.info('Unknown type for standard_scale, ignored')

if dendrogram:
dendro_data = _reorder_categories_after_dendrogram(adata, groupby, dendrogram,
var_names=var_names,
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions scanpy/tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ def test_matrixplot():
sc.pl.matrixplot(adata, adata.var_names, 'cell_type', use_raw=False, dendrogram=True, show=False, swap_axes=True)
save_and_compare_images('master_matrixplot_swap_axes', tolerance=15)

# test var/group standardization
sc.pl.matrixplot(adata, adata.var_names, 'cell_type', use_raw=False, dendrogram=True, show=False, standard_scale='var')
save_and_compare_images('master_matrixplot_std_scale_var', tolerance=15)
sc.pl.matrixplot(adata, adata.var_names, 'cell_type', use_raw=False, dendrogram=True, show=False, standard_scale='group')
save_and_compare_images('master_matrixplot_std_scale_group', tolerance=15)

# test matrixplot numeric column and alternative cmap
adata.obs['Gata2'] = adata.X[:, 0]
sc.pl.matrixplot(adata, adata.var_names, 'Gata2', use_raw=False,
Expand Down