Enriching data points with annotations
The matplotlib.Axes.text(...)
method adds a text box to our plots:
ax.text(1, 10000, 'Generated using numpy and matplotlib') fig
The output is as follows:

Figure 5.8 – Plot displaying Matplotlib text annotations
The matplotlib.Axes.annotate(...)
method provides more control over the annotations.
The code block that follows uses the following parameters to control the annotation:
- The
xy=
parameter specifies the location of the data point. - The
xytext=
parameter specifies the location of the text box. - The
arrowprops=
parameter accepts a dictionary specifying parameters to control the arrow from the text box to the data point. - The
facecolor=
parameter specifies the color and theshrink=
parameter specifies the size of the arrow. - The
horizontalalignment=
andverticalalignment=
parameters specify the orientation of the text box relative to the data point.
The code...