
If you use Matlab-like style in the interactive plotting, then you could use plt.gca() to get the reference of the current axes of the subplot and combine set_title() or t_text() method to set title to the subplots in Matplotlib. We can also add title to subplots in Matplotlib using ttext () method, in similar way to settitle () method.
#Plt subplot title code
So to create multiple plots you will need several lines of code with the subplot () function.

It is similar to the subplots () function however unlike subplots () it adds one subplot at a time. Plt.gca().set_title() / _text() to Set Title to Subplots in Matplotlib ttext () Method to Set Title of Subplots in Matplotlib. subplot () function adds subplot to a current figure at the specified grid position. import numpy as npĪx.t_text("Cosine function")Īx.t_text("Sigmoid function")Īx.t_text("Exponential function") We can also add title to subplots in Matplotlib using t_text() method, in similar way to set_title() method. t_text() Method to Set Title of Subplots in Matplotlib If we want to loop over some subplots and show them one at a time along with titles, we can use the following shorter code: import numpy as np

import numpy as npĪx.set_title("Exponential function") We use matplotlib.axes._title(label) method to set title (string label) for the current subplot Axes. Set_title() Method to Add Title to Subplot in Matplotlib We use set_title(label) and t_text(label) methods to add titles to subplots in Matplotlib. Create a figure with separate subplot titles and a centered figure title. It returns the same figure and axis array that subplots does. Add a title to each subplot, and then add an overall title to the subplot grid. The code is a riff on () with an additional argument for row titles.

PS: if this code give error like ImportError: libtk8.6.so: cannot open shared object file esp. You can easily tweak the fontsize of both and adjust there placing by changing the first two figtext positional parameters.Īlternatively, import matplotlib.pyplot as pltįig = plt.figure() # Creates a new figureįig.suptitle('Temperature', fontsize=50) # Add the text/suptitle to figureĪx = fig.add_subplot(111) # add a subplot to the new figure, 111 means "1x1 grid, first subplot"įig.subplots_adjust(top=0.80) # adjust the placing of subplot, adjust top, bottom, left and right spacingĪx.set_title('Humidity',fontsize= 30) # title of plotĪx.set_xlabel('xlabel',fontsize = 20) #xlabelĪx.set_ylabel('ylabel', fontsize = 20)#ylabelĪx.plot(x,y,'-o') #plotting the data with marker '-o'Īx.axis() #specifying plot axes lengths
