So far, we have seen how to set text at preset locations, such as title and axes. In this recipe, we are going to see how to add text at any location using text boxes.
matplotlib has a very flexible function called pyplot.text()
, that displays text:
import numpy as np import matplotlib.pyplot as plt X = np.linspace(-4, 4, 1024) Y = .25 * (X + 4.) * (X + 1.) * (X - 2.) plt.text(-0.5, -0.25, 'Brackmard minimum') plt.plot(X, Y, c = 'k') plt.show()
This script displays text next to a curve: