首页 > 解决方案 > 从 plt.plot 中删除最后一个 while 循环

问题描述

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

在此处输入图像描述

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

这是代码:

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))

标签: pythonnumpymatplotlibmatplotlib-animation

解决方案


试试这个删除最后一行:

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))

告诉我它是否有用。问候


推荐阅读