I am generating dotplots using scanpy
and unable to change the font size. Is there a way to do so?
For example, how would I edit this line of code?
sc.pl.dotplot(df, ["gene"], 'CellType', dendrogram=True, save = name)
IIRC, scanpy just uses matplotlib under the hood, so there are several options:
You can set the fontsize globally:
import matplotlib.pyplot as plt
plt.rcParams.update({'font.size': 'large'})
You can update specifically only the fontsize of (all) axis labels:
plt.rcParams.update({'axes.labelsize' : 'large'})
plt.rcParams.update({'axes.xtick.labelsize' : 'large'})
plt.rcParams.update({'axes.ytick.labelsize' : 'large'})
Finally, if you have a handle of the axis, you can change the fontsize of labels by traversing the axis attributes:
dp_object = sc.pl.dotplot(df, ["gene"], 'CellType', dendrogram=True, save = name)
axes_dict = dp_object.get_axes()
# figure out which axis you want by printing the axes_dict
# print(axes_dict)
ax = axes_dict[...]
ax.xaxis.label.set_fontsize(22)
for label in ax.get_xticklabels():
label.set_fontsize('large')