Course contentsShow
← Data Science
Lesson 1297 of 2,14532. Visualization with Matplotlib and SeabornFree lesson

Font Properties and Text Styling

Customizing fonts, sizes, weights, and text properties for titles, labels, and annotations across plots.

Font Properties and Text Styling

You'll learn how to customize fonts, sizes, weights, and text properties to make your plot titles, labels, and annotations clear, professional, and perfectly readable.

Why Text Styling Matters

Think of fonts in visualizations like typography in a presentation—the right choices guide your audience's attention and ensure nobody squints or misreads critical information. Poor font choices can make even brilliant insights look amateur or difficult to parse.

Core Text Properties

In both Matplotlib and Seaborn, you can control several key text properties:

  • Font family: The typeface itself (e.g., 'serif', 'sans-serif', 'monospace', or specific names like 'Arial')
  • Font size: Measured in points; larger for titles, smaller for tick labels
  • Font weight: 'normal', 'bold', 'light', or numeric values (100-900)
  • Font style: 'normal', 'italic', or 'oblique'
  • Color: Any valid Matplotlib color specification

Applying Text Styling

You can set these properties when creating text elements:

plt.title('Sales Trends', fontsize=16, fontweight='bold', fontfamily='sans-serif')
plt.xlabel('Month', fontsize=12, fontstyle='italic', color='darkblue')
plt.ylabel('Revenue ($)', fontsize=12, fontweight='normal')

For annotations, pass a dictionary of properties:

plt.text(x, y, 'Peak', fontsize=10, fontweight='bold', color='red')

You can also set global defaults via rcParams to maintain consistency across all plots without repetition.

Key Takeaway: Customizing font properties—family, size, weight, and style—transforms raw plots into polished, readable visualizations that communicate insights effectively and professionally.