[英]Why isn't my plt.plot() working when graphing projectile motion?
I'm graphing projectile motion without/with air friction and I'm now on the first part, which is the one without air friction.我正在绘制没有/有空气摩擦的弹丸运动,我现在在第一部分,这是没有空气摩擦的部分。
After I've put the plt.plot(x_nodrag,y_nodrag), it suppose to draw a curved line of the projectile motion.在我放好 plt.plot(x_nodrag,y_nodrag) 之后,它应该画出弹丸运动的曲线。 But for some reasons it's not being drawn even as the data of the them are being print.但是由于某些原因,即使正在打印它们的数据,它也没有被绘制出来。 I want to know why.我想知道为什么。
I know there might be a lot of errors in this code.. Feel free to point them out if you'd like to.我知道这段代码中可能有很多错误。如果您愿意,请随时指出它们。 Thank you guys for the help.谢谢你们的帮助。
Here's the picture of the graph: https://i.stack.imgur.com/znFLM.png这是图表的图片: https://i.stack.imgur.com/znFLM.png
import numpy as np
import matplotlib.pyplot as plt
# Model parameters
M = 1.0 # Mass of projectile in kg
g = 9.8 # Acceleration due to gravity (m/s^2)
V = 80 # Initial velocity in m/s
ang = 60.0 # Angle of initial velocity in degree
Cd = 0.005 # Drag coefficient
dt = 0.5 # time step in s
# Set up the lists to store variables
# Start by putting the initial velocities at t=0
t = [0] # list to keep track of time
vx = [V*np.cos(ang/180*np.pi)] # list for velocity x and y components
vy = [V*np.sin(ang/180*np.pi)]
#show the projectile motion without drag force
t1=0
vx_nodrag=V*np.cos(ang/180*np.pi)
vy_nodrag=V*np.sin(ang/180*np.pi)
while (t1 < 100):
x_nodrag=vx_nodrag*t1
y_nodrag=vy_nodrag*t1+(0.5*-9.8*t1**2)
plt.ylim([0,200])
plt.xlim([0,270])
plt.plot(x_nodrag,y_nodrag)
print(x_nodrag,y_nodrag)
t1=t1+dt
plt.show()
The command plt.plot
does not work for individual points.命令plt.plot
不适用于单个点。 Use plt.scatter(x_nodrag, y_nodrag)
instead, or collect the consecutive coordinates into lists or arrays and then plot the entire graph at once.使用plt.scatter(x_nodrag, y_nodrag)
代替,或将连续坐标收集到列表或 arrays 然后 plot 一次整个图。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.