I have a very basic question : how to do a line break with matplotlib in python with an \"annotate\" command. I tried \"\\\" and \"\\n\" but it does not work. And how to do
However, if you needed both, consider the following example:
import matplotlib.pyplot as plt
a = 1.23
b = 4.56
annotation_string = r"Need 1$^\mathsf{st}$ value here = %.2f" % (a)
annotation_string += "\n"
annotation_string += r"Need 2$^\mathsf{nd}$ value here = %.2f" % (b)
plt.annotate(annotation_string, xy=(0.5, 0.5))
plt.show()
Which gives you:

The key is to assemble the string beforehand, using +=. That way, you can have the raw-string commands (indicated by r) and the line-break (\n) in the same annotation.