我试图用这个情节创建一个动画,随着'beta'的增加,曲线会拉伸,但我不能。拜托,有人可以帮助我吗?
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
# Data:
mu = 1
e = 1
a = 1
c = 1
beta = np.linspace(0.0 ,0.5,25)
C = (mu*((e*a)**2)) / (16*(np.pi**2)*c)
theta = np.linspace(-2 * np.pi, 2 * np.pi, 200)
fig = plt.figure(figsize=(6,6))
ax = plt.subplot(111, polar=True)
for i in range(len(beta)):
b = beta[i]
r = ((np.sin(theta))**2) / ((1 - b*np.cos(theta))**5)
dP = C*r
ax.plot(theta, dP)
ax.set_yticklabels([])
if i==10000:
break
plt.show()
答案 0 :(得分:1)
您必须创建一个负责更新图表的函数,在这种情况下,我将其称为update()
,如下所示:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
# Data:
mu = 1
e = 1
a = 1
c = 1
beta = np.linspace(0.0 ,0.5,25)
C = (mu*((e*a)**2)) / (16*(np.pi**2)*c)
theta = np.linspace(-2 * np.pi, 2 * np.pi, 200)
fig = plt.figure(figsize=(6,6))
ax = plt.subplot(111, polar=True)
line, = ax.plot([],[])
def update(b):
r = (np.sin(theta)**2)/(1 - b*np.cos(theta))**5
dP = C*r
line.set_xdata(theta)
line.set_ydata(dP)
return line,
ani = FuncAnimation(fig, update, frames=beta, blit=True)
plt.show()