我试着用这个图创建一个动画,随着“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()
发布于 2018-06-08 04:27:31
您必须创建一个负责更新图形的函数,在本例中,我将其命名为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()
https://stackoverflow.com/questions/50748833
复制相似问题