I'm trying to annotate my pyplot with the following: enter image description here

I am able to get the square root of a number, and I am able to get the h-squared, but when I put them together I get a

ValueError: cannot switch from automatic field numbering to manual field specification 

Any idea what I'm doing wrong?

import matplotlib.pyplot as plt x = [1, 2, 3] y = np.array([[1, 2], [3, 4], [5, 6]]) plt.plot(x, y) t=97.35713828629935 plt.text(1,5,r'{:3.1f}% greater than $$\sqrt{0.5*$h^2$}$$'.format(t)) 

1 Answer

The problem is the second pair of {} confuses .format. Use double {{}} to escape them.

plt.text(1,5,r'{:3.1f}% greater than $\sqrt{{0.5 * h^2}}$'.format(t))

0

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy