Matplotlib - Title Font Family


Matplotlib - Title Font Family

Matplotlib - Title Font Family
Title fontfamily="Futura"

To set a specific font family for the title of the plot in Matplotlib, you can use fontfamily of the title() function.

plt.title('Sample Plot', fontfamily='serif')

You can replace 'serif' with other font family names such as 'sans-serif', 'monospace', or specific font names like 'Times New Roman' depending on your preference.

This customization allows you to tailor the appearance of your plot title to match the overall style of your visualizations.

1. "cursive" font family for Title in Maplotlib

In the following program, we shall specify 'cursive' as font family for the title.

Python Program

import matplotlib.pyplot as plt

# Example data
x = [1, 2, 3, 4, 5]
y = [20, 30, 55, 70, 60]

# Plot line
plt.plot(x, y, marker='o')

# Set title, with font family
plt.title('Sample Plot', fontfamily='cursive')

# Show the plot
plt.show()

Output

Matplotlib - Title Font Family - cursive

2. "sans" font family for Title in Maplotlib

In the following program, we shall specify 'cursive' as font family for the title.

Python Program

import matplotlib.pyplot as plt

# Example data
x = [1, 2, 3, 4, 5]
y = [20, 30, 55, 70, 60]

# Plot line
plt.plot(x, y, marker='o')

# Set title, with font family
plt.title('Sample Plot', fontfamily='sans')

# Show the plot
plt.show()

Output

Matplotlib - Title Font Family - sans

3. "Futura" font family for Title in Maplotlib

In the following program, we shall specify 'cursive' as font family for the title.

Python Program

import matplotlib.pyplot as plt

# Example data
x = [1, 2, 3, 4, 5]
y = [20, 30, 55, 70, 60]

# Plot line
plt.plot(x, y, marker='o')

# Set title, with font family
plt.title('Sample Plot', fontfamily='Futura')

# Show the plot
plt.show()

Output

Matplotlib - Title Font Family - Futura