Annotations are one of the most helpful tools for building a strong visual argument. While it may seem like “the data should speak for itself” or that a visualization should be obvious with no textual help, this is far from the truth.

Viewers almost always need and appreciate annotations to add depth and value to their understanding of a data visualization.

Even though we add annotations to a graph, good annotations can actually be one of the best ways to reduce clutter and keep graphs clean – because of what they allow us to drop elsewhere. Depending on the graph, annotations can replace legends, axes labels, or paragraphs of description outside the graph.

And adding annotations is relatively simple: we can use plt.annotate(), and pass in parameters for text and (xy) position.

plt.annotate(‘Look at this point!’, (15, 35))

plt.annotate() also takes many more parameters for more detailed annotations, including:

  • fontsize and color
  • ha and va to set horizontal and vertical alignment
  • backgroundcolor

In this exercise, we’ll use annotations to replace our x-axis labels and improve our use of space and make the figure appear less crowded.



To start, run the Setup cell. Then, we’ll work on the cell below to improve the graph we made in the last exercise. Let’s take advantage of all the empty space we have at the top-right side of each graph and replace the x-axis (where real estate is already very crowded). Create annotations for ‘Primary Forest’, ‘Secondary Forest’, and ‘Selectively Logged Forest’ and position them in the top right corner – xy coordinates of (95, 80). Delete the xlabel line for each graph.


That definitely helps the axes to have more room, but these annotations don’t look great yet. Add some formatting: set the font size to 18, the horizontal alignment to 'right', and the background color to 'lightgray'.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?