How to change Y Axis label size in matplotlib

448 views Asked by At

I am using scanpy, who uses matplotlib under the hood. I am basically creating a dotplot with this package. I would like to change the y axis label size, how can I do this?

Using this works for enlarging all font sizes for the entire plot, as expected:

import scanpy as sc
import matplotlib
import matplotlib.pyplot as plt
from matplotlib import rcParams


#generate the dotplot
plt.rcParams['font.size'] = 50
sc.pl.dotplot(df,  ["gene"], 'CellType',figsize=(5,15), dendrogram=False)

But if I try to do this for the y axis only, it doesn't work:

plt.rcParams['ytick.labelsize']: 5
sc.pl.dotplot(df,  ["gene"], 'CellType',figsize=(5,15), dendrogram=False)

I also tried plt.rcParams.update({'ytick.labelsize': 50}) but that didn't work either. Any help is appreciated!

1

There are 1 answers

0
Dominic McLoughlin On

Changing the rcParams may only affect plots drawn after that command. Try adding

plt.gca().tick_params(axis='y', labelsize=30)

to your code. Here is a minimal working example:

import matplotlib.pyplot as plt

plt.scatter([1, 2, 3], [1, 2, 3])
plt.gca().tick_params(axis='y', labelsize=30)
plt.show()