1

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 1

1

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

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.