How to change the font size of the Title in a Matplotlib figure ?
In this article, we are going to discuss how to change the font size of the title in a figure using matplotlib module.
As we use matplotlib.pyplot.title() method to assign a title a plot, so in order to change the font size, we are going to use the fontsize argument of the pyplot.title() method in the matplotlib module.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course
Below is are some programs which depict how to change the font size of the title in a matplotlib figure:
Example 1:
Python3
# importing moduleimport matplotlib.pyplot as plt# assigning x and y coordinatesx = [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5]y = []for i in range(len(x)): y.append(max(0, x[i]))# depicting the visualizationplt.plot(x, y, color='green')plt.xlabel('x')plt.ylabel('y')# displaying the titleplt.title("ReLU Function", fontsize = 40) |
Output:

Example 2:
Python3
# importing modulesfrom matplotlib import pyplot as plt# assigning x and y coordinatesfoodPreference = ['Vegetarian', 'Non Vegetarian', 'Vegan', 'Eggitarian']consumers = [30, 100, 10, 60]# depicting the visualizationfig = plt.figure()ax = fig.add_axes([0, 0, 1, 1])ax.axis('equal')ax.pie(consumers, labels = foodPreference, autopct='%1.2f%%')# displaying the titleplt.title("Society Food Preference", fontsize = 10) |
Output:

Example 3:
Python3
# importing modulesfrom matplotlib import pyplotimport numpy# assigning time values of the signal# initial time period, final time period# and phase anglesignalTime = numpy.arange(0, 100, 0.5)# getting the amplitude of the signalsignalAmplitude = numpy.sin(signalTime)# depicting the visualizationpyplot.plot(signalTime, signalAmplitude, color = 'green')pyplot.xlabel('Time')pyplot.ylabel('Amplitude')# displaying the titlepyplot.title("Signal", fontsize = 30) |
Output:



