0

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?

enter image description here

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Note also that fontsize can be specified as a number that specifies the size in points as done here, or as a string ('xx-small', 'x-small', ... 'xx-large'). Search for 'fontsize' on this page for more info.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.