Sc.pl.rank_genes_groups_heatmap - saving figure to file

The sc.pl.rank_genes_groups_heatmap() documentation states that save= is “deprecated in favour of sc.pl.plot(show=False).figure.savefig()

I’ve tried adapting the example code in the documentation to my interpretation of the above:

# same as documentation
import scanpy as sc
adata = sc.datasets.pbmc68k_reduced()
sc.tl.rank_genes_groups(adata, 'bulk_labels')
# edited from here
sc.pl.rank_genes_groups_heatmap(adata, show=False).figure.savefig('test.png')

However, I am getting the error:

AttributeError: 'dict' object has no attribute 'figure'

Am I misinterpreting something or is the deprecation still in progress?

Thank you!

PS: At the moment, the deprecated save= argument still works, but I’m just keen to learn best practices going forward.

I think it’s most straightforward to save it using matplotlib directly:

import scanpy as sc
import matplotlib.pyplot as plt

adata = sc.datasets.pbmc68k_reduced()
sc.tl.rank_genes_groups(adata, "bulk_labels")
sc.pl.rank_genes_groups_heatmap(adata, show=False)
plt.savefig("test.png")