Matplotlib Ref Labels
* * Matplotlib Reference Documentation](#)
Matplotlib provides a set of functions for setting chart titles, axis labels, and super titles, which are the foundation for making charts complete and readable.
## Related Functions
| Function | Description | Corresponding Axes Method |
| --- | --- | --- |
| title() | Set Axes title | ax.set_title() |
| xlabel() / ylabel() | Set x/y axis labels | ax.set_xlabel() / ax.set_ylabel() |
| suptitle() | Set Figure super title | fig.suptitle() |
| supxlabel() / supylabel() | Set Figure-level x/y axis labels | fig.supxlabel() / fig.supylabel() |
## Function Definitions
matplotlib.pyplot.title(label, fontdict=None, loc=None, pad=None, *, y=None, **kwargs) matplotlib.pyplot.xlabel(xlabel, fontdict=None, labelpad=None, *, loc=None, **kwargs) matplotlib.pyplot.ylabel(ylabel, fontdict=None, labelpad=None, *, loc=None, **kwargs) matplotlib.pyplot.suptitle(t, **kwargs) matplotlib.pyplot.supxlabel(t, **kwargs) matplotlib.pyplot.supylabel(t, **kwargs)
## Common Parameters
| Parameter | Description |
| --- | --- |
| label / xlabel / ylabel / t | Text content (required) |
| fontsize / size | Font size, e.g., 14, 'large', 'x-large' |
| fontweight / weight | Font weight: 'normal', 'bold', 'light' |
| color | Text color |
| fontdict | Font properties dictionary, e.g., {'fontsize':14, 'color':'blue'} |
| loc | Alignment position: 'center' (default), 'left', 'right' |
| pad / labelpad | Spacing between text and axis/chart edge (in points) |
| y (for title) | Vertical position of title (Axes coordinate, 1.0 is top) |
> `Axes` object methods are named with `set_` prefix, such as `ax.set_title()`, `ax.set_xlabel()`, which is the recommended approach for the object-oriented interface.
* * *
## Usage Examples
### Example 1: Basic Title and Labels
## Example
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0,10,100)
y = np.sin(x) * np.exp(-x/5)
fig, ax = plt.subplots(figsize=(8,4), layout='constrained')
ax.plot(x, y,'steelblue', linewidth=2)
# Set title (Axes level)
ax.set_title('Damped Sine Wave', fontsize=14, fontweight='bold')
# Set axis labels
ax.set_xlabel('Time (seconds)', fontsize=12)
ax.set_ylabel('Amplitude (V)', fontsize=12)
ax.grid(True, alpha=0.3)
plt.show()
### Example 2: Figure Super Title + Axis Labels
## Example
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0,10,100)
fig, axes = plt.subplots(2,2, figsize=(10,8),
layout='constrained')
# Each subplot has its own title
axes[0,0].plot(x, np.sin(x)); axes[0,0].set_title('sin(x)')
axes[0,1].plot(x, np.cos(x)); axes[0,1].set_title('cos(x)')
axes[1,0].plot(x, np.sin(2*x)); axes[1,0].set_title('sin(2x)')
axes[1,1].plot(x, np.cos(2*x)); axes[1,1].set_title('cos(2x)')
# Figure-level super title
fig.suptitle('Trigonometric Functions Overview',
fontsize=16, fontweight='bold', y=1.02)
# Figure-level axis labels (centered across all subplots)
fig.supxlabel('x (radians)', fontsize=13)
fig.supylabel('Amplitude', fontsize=13)
plt.show()
### Example 3: Title Position and Style
## Example
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0,10,100)
fig,(ax1, ax2)= plt.subplots(1,2, figsize=(10,4),
layout='constrained')
# Left plot: left-aligned title
ax1.plot(x, np.sin(x),'steelblue')
ax1.set_title('Left-aligned Title',
loc='left',# Left aligned
fontsize=12,
color='steelblue')
ax1.set_xlabel('X-axis', fontsize=10, color='gray')
# Right plot: right-aligned title
ax2.plot(x, np.cos(x),'coral')
ax2.set_title('Right-aligned Title',
loc='right',# Right aligned
fontsize=12,
color='coral',
fontstyle='italic')
ax2.set_ylabel('Y-axis', fontsize=10, color='gray',
rotation=0, labelpad=20)# Label not rotated
plt.show()
### Example 4: LaTeX Math Formula Titles
## Example
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(-5,5,200)
fig,(ax1, ax2)= plt.subplots(1,2, figsize=(10,4),
layout='constrained')
# Gaussian distribution
sigma, mu =1.0,0.0
y1 =1/(sigma * np.sqrt(2*np.pi)) * np.exp(-(x-mu)**2/(2*sigma**2))
ax1.plot(x, y1,'steelblue', linewidth=2)
# Use LaTeX formula as title
ax1.set_title(
r'$f(x) = frac{1}{sigmasqrt{2pi}}'
r'expleft(-frac{(x-mu)^2}{2sigma^2}right)$',
fontsize=12)
# Polynomial
y2 = x**3 - 3*x
ax2.plot(x, y2,'coral', linewidth=2)
ax2.set_title(r'$f(x) = x^3 - 3x$', fontsize=14)
ax2.axhline(y=0, color='gray', linewidth=0.5)
for ax in[ax1, ax2]:
ax.set_xlabel('x')
ax.grid(True, alpha=0.3)
fig.suptitle('Functions with LaTeX Titles', fontsize=14,
fontweight='bold')
plt.show()
print("tutorial: LaTeX titles displayed")
* * *
## Common Questions
### What's the difference between title() and suptitle()?
`title()` (or `ax.set_title()`): Sets the title above a single Axes.
`suptitle()` (or `fig.suptitle()`): Sets the super title at the top of the entire Figure, spanning all subplots.
### How to make titles support Chinese?
Set the font: `plt.rcParams['font.sans-serif'] = ['SimHe
YouTip