
Plt.title('Plot 2: 2nd Degree curve', fontsize=15) Plt.title('Plot 1: 1st Degree curve', fontsize=15) Plt.suptitle('Different degree curves', fontsize=19) Let’s practice an example: # Import necessary libraries We can specify the font size of the title text (for both figure title and subplot title) in the matplotlib by adding a parameter fontsize with the necessary integer value of the size of the font in the () or/and () function. Plt.title('Plot 4: 4th Degree curve', fontsize=15) Plt.title('Plot 3: 3rd Degree curve', fontsize=15) Read: Matplotlib plot a line Matplotlib subplot title bold We have adjusted the size of the fonts of the title text of the figure and the subplots. Plt.suptitle('Different degree curves', fontsize=19, fontweight='bold') We can make the font of the title text to be bold (for both figure title and subplot title) in the matplotlib by adding a parameter fontweight with the necessary integer value (600+ for the bold font) or the string ‘bold’ in the () or/and () function.

Read: modulenotfounderror: no module named ‘matplotlib’ Matplotlib subplot title position We have changed the font-weight to make the title text bold for the figure. We can specify the position of the title text of the figure by adding two more parameters x and y in the () function. Plt.suptitle('Different degree curves', x=0.5, y=0, fontsize=17, fontweight='700') Let’s see how can we implement the concept: # Import necessary libraries The values to the x and y parameters represent the x and y coordinates respectively in the figure coordinates. Plt.title('Plot 4: 4th Degree curve', loc='right', fontsize=15) Plt.title('Plot 3: 3rd Degree curve', loc='left', fontsize=15) Plt.title('Plot 2: 2nd Degree curve', loc='right', fontsize=15) Plt.title('Plot 1: 1st Degree curve', loc='left', fontsize=15)
#MATPLOTLIB ADD SUBPLOT TITLE HOW TO#
Read: How to install matplotlib python Matplotlib subplot title padding We have set the different positions of the various title texts in the figure. We can adjust the padding of the title text of the figure by adding a parameter y in the () function and can add either y or the pad parameter in the () function. Plt.title('Plot 4: 4th Degree curve', fontsize=15, pad=17) Plt.title('Plot 3: 3rd Degree curve', fontsize=15, pad=17) Plt.title('Plot 2: 2nd Degree curve', fontsize=15, y=1.1) Plt.title('Plot 1: 1st Degree curve', fontsize=15, y=1.1) Plt.suptitle('Different degree curves', y=1.1, fontsize=19, fontweight='bold') Let’s see an example to understand the concepts better: # Import necessary libraries The value to the y parameters represents the y-coordinate in the figure coordinates and the value of the pad represents the gap/padding of the title text from the plot/subplot. Note that we additionally passed the font size we want the title to have with the fontsize parameter.We have adjusted the padding of the title text of the figure and subplots. # create subplotsįig.suptitle("Foregin currency performance against USD", fontsize=18) Let’s add an overall title to the above grid of subplots.


In case you want to set the title of the entire figure, you can use the fig object’s suptitle() method. Example 2 – Add a title to the entire figure # create subplotsĮach subplot now has its own title. Let’s see how we can separately set the title for each subplot. Here, we plotted the same scatter plot in both subplots but that is not important. Output: Example 1 – Add a different title to each subplot

First, we will a plot with two subplots without any titles. Let’s now look at some examples of using the above syntax. The following is the syntax – # create a plot with two subplots To set the titles for subplots, however, you have to use the respective subplot’s axes object’s set_title() method. When you’re working with a single plot, you can use the matplot.pyplot object’s title() method to set its title. In this tutorial, we will look at how to add a different title to each subplot in matplotlib with the help of some examples.
