JavaScript
x
11
11
1
import matplotlib.pyplot as plt
2
import sympy as sp
3
import numpy as np
4
5
q = [3,5]
6
t,i = sp.symbols('t,i')
7
eq = t**2/(q[1]-(t/q[0])**2)
8
x = np.linspace(0,100,10000)
9
y=x**2
10
plt.plot(x,y)
11
Now I want to display the sympy equation “eq” on the plot. I have seen many methods to display the same equation using tex commands, but I specifically want to display the sympy eq. Thanks in advance
Advertisement
Answer
You could use sympy’s latex()
function like this:
JavaScript
1
13
13
1
import matplotlib.pyplot as plt
2
import sympy as sp
3
import numpy as np
4
5
q = [3,5]
6
t,i = sp.symbols('t,i')
7
eq = t**2/(q[1]-(t/q[0])**2)
8
x = np.linspace(0,100,10000)
9
y=x**2
10
plt.plot(x,y, label=r"$" + f"{sp.latex(eq)}" + r"$")
11
plt.legend()
12
plt.show()
13