WeCodeAcademy

Annotations and Reference Lines

Often the most useful thing on a chart is a sentence pointing at the one place that matters. ax.annotate('text', xy=(x, y), xytext=(x2, y2), arrowprops=dict(arrowstyle='->')) writes a note and draws an arrow to the point xy. ax.axhline(y=value) draws a horizontal reference line such as a target, an average or a safe limit; ax.axvline(x=value) does the same vertically.

Use annotations sparingly: one or two notes guide the reader, ten make noise.

Examplepython
Open in editor »
Quick check

Which call draws a horizontal line across the whole chart?

Your turn: write the code

Add a horizontal reference line at 50 and one annotation with the text 'Pass mark', then print the number of lines and the number of text notes on one line separated by a space (use len(ax.get_lines()) and len(ax.texts)).

Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.

Tip: use the left and right arrow keys to move between lessons.