Suggest you should try:
ax = sc.pl.scatter(adata, x = 'total_counts', y='pct_counts_mt',show=False)
ax.set_ylim(0,50);
Explanation
The key that I found to making this work is based on a note in Workhorse's comment under here in which they noted you needed the setting return_fig=True
for sc.pl.dotplot()
. Looking at the scanpy.pl.scatter
documentation, it seems the equivalent is the show
setting.
"Show the plot, do not return axis."
I had been seeing the sc.pl.scatter()
based on something like the OP had was returning nothing. Adding in show=False
will get a matplotlib axes object (matplotlib.axes._axes.Axes
) returned that can then be adjusted using ax.set_ylim()
, similar to ivirshup's suggestion here. (ivirshup had show=False
in use there; however, I didn't pick up on that until seeing Workhorse's comment and what is returned by scanpy.pl.scatter
isn't iterable so that the use of for ax...
or with ax...
doesn't work, like apparently for ax...
works [or worked?] for sc.pl.rank_genes_groups_violin()
.)
Applying that to your case, I suggest you should use:
ax = sc.pl.scatter(adata, x = 'total_counts', y='pct_counts_mt',show=False)
ax.set_ylim(0,50);
(You can leave off the semi-colon if the ax.set_ylim(0,50)
won't be the last line in a Jupyter cell.)
That suggestion likely working is supported by testing in Jupyter sessions provided by the MyBInder service launched from here where the steps to install scanpy
under here were followed and then the first couple of code cells in the included 'analysis-visualization-spatial.ipynb' run to define an annotated data matrix adata
, before using this code to test the plotting of a scatter plot like OP was using:
ax = sc.pl.scatter(adata, x = 'total_counts', y='pct_counts_in_top_50_genes',show=False)
ax.set_ylim(0,50);
your answer is the most correct one. Worship