How to change the axis limits in scanpy for violin plots

How do you change the axis limits in ScanPy for violin plots? Is this possible?

specifically for this type of plot

sc.pl.violin(adata, keys='total_counts', groupby='leiden',  xlabel="leiden cluster number", save="_leiden_clusters_total_counts")

Hi! You can get back the Axes object and manipulate e.g. the y-axis limits like so:

ax = sc.pl.violin(adata, keys='total_counts', groupby='leiden',  xlabel="leiden cluster number", show=False)
ax.set_ylim(bottom=0,top=100)

Of course don’t forget to save the plot afterwards, as now this will not happen automatically.

1 Like