What exactly did you try?
Were you, by chance, using a raw string (e.g. r"whatever"
)?
'\n'
works perfectly, but if you're using a raw string to avoid latex sequences being interpreted as an escape, it will be interpreted by python as '\'
and 'n'
instead of a newline.
As an example:
import matplotlib.pyplot as plt
plt.annotate('Testing\nThis\nOut', xy=(0.5, 0.5))
plt.show()

On the other hand, if we use a raw string:
import matplotlib.pyplot as plt
plt.annotate(r'Testing\nThis\nOut', xy=(0.5, 0.5))
plt.show()
