How can I annotate outside of the grid?
The annotation “local max” is annotated correctly. However, the annotation “outside” is not displayed at all. How can I display an annotation if its coordinates are placed outside of the grid?
import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots(figsize=(3, 3))
t = np.arange(0.0, 5.0, 0.01)
s = np.cos(2*np.pi*t)
line, = ax.plot(t, s, lw=2)
ax.annotate('local max', xy=(2, 1), xytext=(3, 1.5),
arrowprops=dict(facecolor='black', shrink=0.05))
ax.annotate('outside', xy=(3, -2.25), xytext=(0, 1),
arrowprops=dict(facecolor='black', shrink=0.05))
ax.set_ylim(-2, 2)