Python: How to increase / decrease font size of x and y ticks?

I seem to have a problem in determining how to increase or decrease the fontsizex and y tick labels when using matplotlib.

I know that there is a function set_xticklabels(labels, fontdict=None, minor=False, **kwargs), but I did not understand how to manage fontsizeit.

I was expecting something explicitly, like

title_string=('My Title')
plt.suptitle(title_string, y=1.0, fontsize=17)

but I haven’t found anything like it yet. What am I missing?

+6
source share
4 answers

This is easier than I thought.

To set the font size to type x:

x_ticks=['x tick 1','x tick 2','x tick 3']
ax.set_xticklabels(x_ticks, rotation=0, fontsize=8)

Do it for ticks of galaxy y:

y_ticks=['y tick 1','y tick 2','y tick 3']
ax.set_yticklabels(y_ticks, rotation=0, fontsize=8)

Arguments rotationand fontsizecan easily control what happened after.

: http://matplotlib.org/api/axes_api.html

+3

set_xticklabels set_yticklabels ( ). Axes .

ax.set_xticklabels(x_ticks, rotation=0, fontsize=8)
ax.set_yticklabels(y_ticks, rotation=0, fontsize=8)

ticklabel (.. / script) rcParams

import matplotlib.pyplot as plt

plt.rc('xtick',labelsize=8)
plt.rc('ytick',labelsize=8)

, :

plt.rcParams['xtick.labelsize']=8
plt.rcParams['ytick.labelsize']=8

, , matplotlib, rcParams matplotlibrc :

xtick.labelsize      : 8 # fontsize of the x tick labels
ytick.labelsize      : 8 # fontsize of the y tick labels
+10

size fontsize.

+1

set_yticklabels , ( FixedFormatter), . - tick_params:

ax.tick_params(axis="x", labelsize=8)
ax.tick_params(axis="y", labelsize=20)

ax.tick_params(labelsize=8)

if both axes are the same size.

Of course, using rcParams, as in @tmdavison's answer, is also possible.

0
source

Source: https://habr.com/ru/post/1617996/


All Articles