I've been trying to code projectile motion and everything has been working so far except the graphing portion, which i'm trying to iterate within the loop. I want to graph the x and y coordinate of the position vector, but i keep getting the error "module not callable"
import numpy as np
import math as m
import matplotlib as plt
g = np.array([0,-9.8,0])
r = np.array([0,1.2,0])
theta = 35 * m.pi / 180
v1 = 3.3
v = v1 * np.array([np.cos(theta),np.sin(theta),0])
a = g
t = 0
dt = .01
while r[1] > 0:
v = v + a * dt
r = r + v * dt
t = t + dt
plt.plot(r)
print("r = ",r , "m")
print("t = ",t, "s")
print("v = ",v, "m/s")
I found two issues in your code:
pltimport is not correct. Instead usefrom matplotlib import pyplot as pltplt.plot(r)works but nothing is shown since you are trying to draw a single point of infinitesimal size for each canvas. Since is a scatterplot, you should assign a dimension to each point, e.g.If your goal is to generate an animation (as suggested by @3dSpatialUser), you need multiple pictures. Thus add
plt.show()(orplt.savefig()) in the while loop.