Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
How to put the title at the bottom of a figure in Matplotlib?
In Matplotlib, you can position the title at the bottom of a figure by adjusting the y parameter in the title() method. This is useful for creating custom layouts or when you want the title to appear below the plot area.
Basic Approach
Use the y parameter in plt.title() to control vertical positioning. Values below 1.0 move the title downward ?
import numpy as np
import matplotlib.pyplot as plt
# Set figure size
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
# Generate sample data
N = 100
x = np.random.rand(N)
y = np.random.rand(N)
# Create scatter plot
plt.scatter(x, y, c=x, s=x*100+1, cmap="plasma")
# Position title at bottom using negative y value
plt.title('Scatter Plot with Bottom Title', y=-0.01)
plt.show()
Different Positioning Options
You can experiment with different y values to achieve the desired positioning ?
import matplotlib.pyplot as plt
import numpy as np
fig, axes = plt.subplots(2, 2, figsize=(10, 6))
x = np.linspace(0, 10, 100)
y = np.sin(x)
# Different y positions for title
positions = [1.02, 0.5, -0.05, -0.15]
labels = ['Above (y=1.02)', 'Middle (y=0.5)', 'Bottom (y=-0.05)', 'Far Bottom (y=-0.15)']
for i, (ax, pos, label) in enumerate(zip(axes.flat, positions, labels)):
ax.plot(x, y)
ax.set_title(label, y=pos)
ax.grid(True, alpha=0.3)
plt.tight_layout()
plt.show()
Using Figure-Level Title
For more control, use fig.suptitle() with y parameter ?
import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots(figsize=(8, 5))
# Sample data
x = np.random.randn(1000)
y = np.random.randn(1000)
ax.scatter(x, y, alpha=0.6, c='blue')
ax.set_xlabel('X values')
ax.set_ylabel('Y values')
# Position figure title at bottom
fig.suptitle('Figure Title at Bottom', y=0.02)
plt.tight_layout()
plt.show()
Key Parameters
| Parameter | Description | Typical Values |
|---|---|---|
y |
Vertical position | -0.15 to -0.01 for bottom |
pad |
Padding from axes | Default: 6.0 |
fontsize |
Title font size | 'large', 'medium', or numeric |
Conclusion
Use y=-0.01 or similar negative values in plt.title() to position titles at the bottom. For figure-level control, use fig.suptitle() with low y values like 0.02.
Advertisements
