How to change the size of axis labels in matplotlib ?

Daidalos July 31, 2019


Examples of how to change the size of axis labels in matplotlib:

Change the size of x-axis labels

A solution to change the size of x-axis labels is to use the pyplot function xticks:

matplotlib.pyplot.xticks(fontsize=14)

example:

#!/usr/bin/env python

import numpy as np
import matplotlib.pyplot as plt
import math

pi = math.pi

x_list = np.arange(-2*pi,2*pi,0.1)
y_list = [math.cos(x) for x in x_list]

plt.plot(x_list,y_list)

plt.xticks(fontsize=14)

plt.grid()
plt.title('Change label axis font size in matplotlib')

plt.savefig("matplotlib_change_label_axis_font_size.png", bbox_inches='tight', dpi=100)
plt.show()

How to change the size of axis labels in matplotlib ?

Another solution is to use tick_params, example:

#!/usr/bin/env python

import numpy as np
import matplotlib.pyplot as plt
import math

pi = math.pi

x_list = np.arange(-2*pi,2*pi,0.1)
y_list = [math.cos(x) for x in x_list]

fig = plt.figure(1)

plot = fig.add_subplot(111)

plt.plot(x_list,y_list)

plot.tick_params(axis='x', labelsize=14)

plt.grid()
plt.title('Change label axis font size in matplotlib')

plt.show()

Change the size of y-axis labels

A solution to change the size of y-axis labels is to use the pyplot function yticks:

matplotlib.pyplot.xticks(fontsize=14)

Example

How to change the size of axis labels in matplotlib ?

References

Links Site
Matplotlib make tick labels font size smaller stackoverflow
xticks matplotlib.org
xticks examples matplotlib.org
yticks matplotlib.org
tick_params matplotlib.org

Licence


Activity


Google Ads