简体   繁体   中英

Different font sizes in python plot

In the following plot, the font size seems to be different for x and y axis. I am not sure what is causing it. I am using the following rcParams:

rcParams['mathtext.default']='regular'
rcParams['axes.labelsize'] = 9
rcParams['xtick.labelsize'] = 9
rcParams['ytick.labelsize'] = 9
rcParams['legend.fontsize'] = 9
rcParams['font.family'] = 'serif'
rcParams['font.serif'] = ['Computer Modern Roman']
rcParams['figure.figsize'] = 7.3, 4.2

and this is how I set the x axis labels:

labels    = [item.get_text() for item in ax.get_xticklabels()]
labels[0] = 'Col A'
labels[1] = 'Col B'
labels[2] = 'Col C'
ax.set_xticklabels(labels,rotation=0)

and this is how I set the y axis label:

ax.set_ylabel('Percentage')

How do I get consistent fonts in x and y axis labels?

在此处输入图片说明

Modify your code to specify fontsizes,

fs=9
ax.set_xticklabels(labels,rotation=0, fontsize=fs)

and,

ax.set_ylabel('Percentage', fontsize=fs)

You can set the y-axis tick fontsizes as,

for tick in ax.yaxis.get_major_ticks():
    tick.label.set_fontsize(fs)

Good luck.

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