Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change the font size of the scale in matplotlib plots?

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.

like image 201
hectorpal Avatar asked Jul 08 '12 01:07

hectorpal


People also ask

How do I change text size in Matplotlib?

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'] .

How do you change the scale of a plot in Matplotlib?

MatPlotLib with Python To change the range of X and Y axes, we can use xlim() and ylim() methods.


1 Answers

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()
like image 82
Cory Dolphin Avatar answered Sep 24 '22 16:09

Cory Dolphin