To enhance the understanding of plot details, we may sometimes add in text annotations for explanation. We will now introduce the methods of adding and adjusting text in Matplotlib plots.
We can add text to our plot by calling plt.text(x,y,text)
; we specify the x
and y
coordinates and the text string.
Here is a quick example:
plt.text(0.25,0.5,'Hello World!',fontsize=30) plt.show()
You can see in this figure the Hello World! message appearing in the center of the plot: