While plotting using Matplotlib, I have found how to change the font size of the labels. But, how can I change the size of the numbers in the scale?
For clarity, suppose you plot x^2 from (x0,y0) = 0,0 to (x1,y1) = (20,20). The scale in the x-axis below maybe something like
0 1 2 ... 20.
I want to change the font size of such scale of the x-axis.
Change Font Size Globally There are two ways we can set the font size globally. We'll want to set the font_size parameter to a new size. We can get to this parameter via rcParams['font. size'] .
MatPlotLib with Python To change the range of X and Y axes, we can use xlim() and ylim() methods.
Matplotlib refers to these as xtick labels. They can be changed in a large number of different ways, passed in as parameters, or iterated through and edited (as in the case of the solution posted here Matplotlib make tick labels font size smaller).
I went ahead and posted a more concise solution, as the former was very inefficient.
from matplotlib import pyplot
import math
def setLabelExample():
fig = pyplot.figure()
x = [i for i in range(200)]
y = [xi**2 for xi in x]
ax = fig.add_subplot(1,1,1)
ax.plot(x, y)
ax.tick_params(axis='x', labelsize=30)
fig.suptitle('Matplotlib xticklabels Example')
pyplot.show()
if __name__ == '__main__':
setLabelExample()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With