So I'm making code that supposed to track how the distance of an object impacts the force it makes, yet for some reason, my list function will only record my last value input into the While loop. In addition, the graph won't even show that value. Im using Matplotlib and SymPy, nothing really extreme for packages. Can someone please help me with these two issues?
import sympy as sy
sy.init_printing()
from sympy import *
import matplotlib.pyplot as plt
x=1
print('Give it a minute please')
List_p = list()
List_x = list()
while x<=750:
theta = atan(400/x)
Fd=10*500*cos(theta)/(x/cos(theta))
p=Fd*sin(theta)
List_p.append(p)
List_x.append(x)
x=x+1
plt.plot([x],[p])
plt.xlim(1,750)
plt.xlabel('Distance')
plt.ylabel('Force of P')
plt.title('Distance V Force of P')
plt.show()
It seems to me that the issue is you're not plotting List_x
and List_p
but rather just x
and p
. Pass the lists to the plot
method instead:
List_p = []
List_x = []
for x in range(1,751):
theta = atan(400/x)
Fd=10*500*cos(theta)/(x/cos(theta))
p=Fd*sin(theta)
List_p.append(p)
List_x.append(x)
plt.plot(List_x, List_p) # <--- here
plt.xlim(1,750)
plt.xlabel('Distance')
plt.ylabel('Force of P')
plt.title('Distance V Force of P')
plt.show()