Search code examples
pythonmatplotlibhistogram

How to change the size of the title and the numbers in a histogram in matplotlib?


I want to increase the size of the title of each histogram and also increase the size of the number in the axis.

axs = regiao_nota_MT['NU_NOTA_MT'].hist(by = regiao_nota_MT['Regiao'], figsize=(15, 10),  facecolor='green',  alpha=0.5)

for ax in axs.flatten():
    ax.set_xlabel("NU_NOTA_MT", size = '13')
    ax.set_ylabel("Number of students", size = '13')

https://i.sstatic.net/AQ92e.png


Solution

  • You can globally set the size of your axes.titles and ytick

    import matplotlib.pyplot as plt
    params = {'ytick.labelsize': 12,
              'axes.titlesize': 12}
    plt.rcParams.update(params)
    

    More on Customizing Matplotlib with style sheets and rcParams