0
0
Matplotlibdata~5 mins

Font size guidelines in Matplotlib

Choose your learning style9 modes available
Introduction

Font sizes help make charts easy to read. Using the right size keeps your labels clear and your graph neat.

When you want your chart titles to stand out.
When axis labels need to be readable without crowding.
When adding legends that explain colors or lines.
When preparing charts for presentations or reports.
When adjusting text for different screen sizes or print.
Syntax
Matplotlib
plt.title('Title', fontsize=SIZE)
plt.xlabel('X label', fontsize=SIZE)
plt.ylabel('Y label', fontsize=SIZE)
plt.legend(fontsize=SIZE)

Replace SIZE with a number (like 10, 12, 14) or a string (like 'small', 'medium', 'large').

You can set font size for titles, labels, and legends separately.

Examples
Sets the chart title font size to 16 points.
Matplotlib
plt.title('My Chart', fontsize=16)
Uses a named size 'large' for the x-axis label.
Matplotlib
plt.xlabel('Time', fontsize='large')
Sets the legend font size to 12 points.
Matplotlib
plt.legend(['Data'], fontsize=12)
Sample Program

This code creates a simple line chart with clear font sizes for the title, axis labels, and legend.

Matplotlib
import matplotlib.pyplot as plt

x = [1, 2, 3, 4]
y = [10, 20, 25, 30]

plt.plot(x, y, label='Sales')
plt.title('Monthly Sales', fontsize=18)
plt.xlabel('Month', fontsize=14)
plt.ylabel('Sales Amount', fontsize=14)
plt.legend(fontsize=12)
plt.show()
OutputSuccess
Important Notes

Font sizes are measured in points (pt). Bigger numbers mean bigger text.

Use consistent font sizes to keep your charts looking professional.

If text overlaps or looks crowded, try increasing the font size or adjusting layout.

Summary

Font sizes improve chart readability.

Set font sizes for titles, labels, and legends separately.

Use numbers or named sizes like 'small', 'medium', 'large'.