python - 为什么我的 plt.plot() 在绘制弹丸运动时不起作用?
问题描述
我正在绘制没有/有空气摩擦的弹丸运动,我现在在第一部分,这是没有空气摩擦的部分。
在我放好 plt.plot(x_nodrag,y_nodrag) 之后,它应该画出弹丸运动的曲线。但是由于某些原因,即使正在打印它们的数据,它也没有被绘制出来。我想知道为什么。
我知道这段代码可能有很多错误!!如果您愿意,请随时指出它们。谢谢你们的帮助。
这是图表的图片: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()
解决方案
该命令plt.plot
不适用于单个点。改为使用plt.scatter(x_nodrag, y_nodrag)
,或将连续坐标收集到列表或数组中,然后一次绘制整个图形。
推荐阅读
- php - Laravel如何加入其他数据库表?
- c# - 如何在一秒钟后触发 MouseEnter 事件
- rest - 为什么我的上传文件 POST 不能使用 NEST.JS 和 Multer 工作?
- ios - 如何将 web 视图首选项添加到 swift ui web 视图
- python - listctrl,列图像不显示
- java - 尽管 java 有大量可用堆,但 VM 内存不足
- python - 在python中叠加条形图
- artificial-intelligence - 有没有办法在 Jason/AgentSpeak 中“抑制”“没有为……生成失败事件”警告/错误?
- javascript - WordPress 版本 5.2。和 Ajax 错误请求 400
- dsl - MPS 中的自定义编辑器