简体   繁体   中英

How to change font size in scanpy

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')

Turns out you can do this directly using scanpy with the following:

sc.set_figure_params(scanpy=True, fontsize=14)

However, I am still unsure how to change the y axis specifically...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM