简体   繁体   中英

Python animation polar plot

I tried to create an animation with this plot, where with the increase of 'beta' the curves go stretching, but I could not. Please, can anyone help me?

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

You have to create a function that is in charge of updating your graph, in this case I'll call it update() as I show below:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM