Chapter 3. Working with Annotations

In this chapter, we will cover the following topics:

  • Adding a title
  • Using LaTeX-style notations
  • Adding a label to each axis
  • Adding text
  • Adding arrows
  • Adding a legend
  • Adding a grid
  • Adding lines
  • Adding shapes
  • Controlling tick spacing
  • Controlling tick labeling

Introduction

It is considered a good practice to make your figures self-explanatory. However, it can be hard to make some curves and dots self-explanatory without any annotations. How should one read the vertical and horizontal axes? Which quantity is represented by that box and this curve? matplotlib offers a great number of possibilities to annotate a figure, which we are going to explore in this chapter.

Get matplotlib Plotting Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.