Set Tick Labels Font Size in Matplotlib
-
plt.xticks(fontsize= )
to Set Matplotlib Tick Labels Font Size -
ax.set_xticklabels(xlabels, Fontsize= )
to Set Matplotlib Tick Labels Font Size -
plt.setp(ax.get_xticklabels(), Fontsize=)
to Set Matplotlib Tick Labels Font Size -
ax.tick_params(axis='x', Labelsize= )
to Set Matplotlib Tick Labels Font Size
In this tutorial article, we will introduce different methods to set tick labels font size in Matplotlib. It includes,
plt.xticks(fontsize= )
ax.set_xticklabels(xlabels, fontsize= )
plt.setp(ax.get_xticklabels(), fontsize=)
ax.tick_params(axis='x', labelsize= )
We will use the same data set in the following code examples.
The codes to create the above figure is,
from matplotlib import pyplot as plt
from datetime import datetime, timedelta
xvalues = range(10)
yvalues = xvalues
fig,ax = plt.subplots()
plt.plot(xvalues, yvalues)
plt.grid(True)
plt.show()
plt.xticks(fontsize= )
to Set Matplotlib Tick Labels Font Size
from matplotlib import pyplot as plt
from datetime import datetime, timedelta
xvalues = range(10)
yvalues = xvalues
fig,ax = plt.subplots()
plt.plot(xvalues, yvalues)
plt.xticks(fontsize=16)
plt.grid(True)
plt.show()
plt.xticks(fontsize=16)
plt.xticks
gets or sets the properties of tick locations and labels of the x-axis.
fontsize
or size
is the property of a Text
instance, and can be used to set the font size of tick labels.
ax.set_xticklabels(xlabels, Fontsize= )
to Set Matplotlib Tick Labels Font Size
set_xticklabels
sets the x-tick labels with a list of string labels, with the Text
properties as the keyword arguments. Here, fontsize
sets the tick labels font size.
from matplotlib import pyplot as plt
from datetime import datetime, timedelta
import numpy as np
xvalues = np.arange(10)
yvalues = xvalues
fig,ax = plt.subplots()
plt.plot(xvalues, yvalues)
plt.xticks(xvalues)
ax.set_xticklabels(xvalues, fontsize=16)
plt.grid(True)
plt.show()
plt.setp(ax.get_xticklabels(), Fontsize=)
to Set Matplotlib Tick Labels Font Size
matplotlib.pyplot.setp
sets a property on an artist object.
plt.setp(ax.get_xticklabels(), fontsize=)
sets the fontsize
property of xtick labels object.
from matplotlib import pyplot as plt
from datetime import datetime, timedelta
xvalues = np.arange(10)
yvalues = xvalues
fig,ax = plt.subplots()
plt.plot(xvalues, yvalues)
plt.setp(ax.get_xticklabels(), fontsize=16)
plt.grid(True)
plt.show()
ax.tick_params(axis='x', Labelsize= )
to Set Matplotlib Tick Labels Font Size
tick_params
sets the parameters of ticks, tick labels, and gridlines.
ax.tick_params(axis='x', labelsize= )
sets the labelsize
property of tick label in x
axis, or in other words, X-axis.
from matplotlib import pyplot as plt
from datetime import datetime, timedelta
xvalues = range(10)
yvalues = xvalues
fig,ax = plt.subplots()
plt.plot(xvalues, yvalues)
ax.tick_params(axis='x', labelsize=16)
plt.grid(True)
plt.show()