【问题标题】:Delete last while cycle from plt.plot从 plt.plot 中删除最后一个 while 循环
【发布时间】:2021-11-04 23:42:31
【问题描述】:

我正在研究一些关于排放锥形罐的欧拉方程,但在绘制模拟图时遇到了问题。

我的目的是在时间增加的同时减小坦克的半径。我想在第一个循环后删除第一条蓝线,但我不知道如何:(

这是代码:

import matplotlib.pyplot as plt
import numpy as np

Hi=0.5
hf=0
r=0.003
ang=8*np.pi/180
teta=np.tan(ang)**2

dt=1
g=9.8
t=0
t1=0
h=Hi
h2=0
R=np.tan(ang)*h
R1=np.tan(ang)*

Vh=[h]
Vt=[t]
Rt=[R]

f1 = plt.figure(1)

plot1=plt.plot([R-r,0,2*R,R+r,R-r],[0,Hi,Hi,0,0],"k")
plot1=line=plt.plot([0,2*R],[h,h],"b")
plt.grid()
plt.ylabel("ALtura del agua")

while h>0 and R>0:
h=((5*((2*g)**(1/2))*r**2)/(-2*teta*((Hi**(3/2)))))*dt+h
R=(np.tan(ang)*h)
t=t+dt

plot1=line=plt.plot([R1-R,R1+R],[h,h],"b")

Vh.append(h)
Vt.append(t)
Rt.append(R)

line[0].set_ydata([h])

plt.pause(1/24)
plt.title("Tiempo = "+str(t))

【问题讨论】:

  • R1=np.tan(ang)* 错字?
  • 对不起,R1=np.tan(ang)*h。我使用这个变量作为最大 h 处的第一个半径。

标签: python numpy matplotlib matplotlib-animation


【解决方案1】:

试试这个删除最后一行:

if h <= 0:
    h = 0

Vh.append(h)
Vt.append(t)
Rt.append(R)
line[0].set_ydata([h])
plt.pause(1/24)
plt.title("Tiempo = " + str(t))

告诉我它是否有用。 问候

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-18
    • 2017-03-24
    • 2013-11-24
    • 2011-06-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多