【发布时间】:2021-11-02 19:11:42
【问题描述】:
有一个简单的代码可以根据一些简单的规则画线。
它可以工作,但我想通过更改一个参数theta_time 来动画它。
import matplotlib.pyplot as plt
import numpy as np
from numpy import *
import matplotlib.animation as animation
List_1 = [6,4,2,1]
List_2 = [0,0,0,0]
List_3 = [6,4,3,2]
fig, ax = plt.subplots()
C_x = 0
C_y = 0
cx = [0]
cy = [0]
theta_time = 1 #I want to update this value from 0 to 10
for freq,amp,phase in zip(List_3,List_1, List_2):
C_x += amp*np.cos(freq * theta_time + np.deg2rad(phase))
C_y += amp*np.sin(freq * theta_time + np.deg2rad(phase))
cx.append(C_x)
cy.append(C_y)
plt.scatter(cx,cy)
plt.plot(cx, cy, '.r-',linewidth=1)
plt.show()
我尝试将以下代码添加到动画中,但它不起作用
def animations(theta_time):
for freq,amp, phase in zip(List_3,List_1, List_2):
C_x += amp*np.cos(freq * theta_time + np.deg2rad(phase))
C_y += amp*np.sin(freq * theta_time + np.deg2rad(phase))
cx.append(C_x)
cy.append(C_y)
ani = animation.FuncAnimation(
fig, animations,frames=np.arange(0,1,0.01),interval=10, blit=False)
【问题讨论】:
标签: python numpy matplotlib animation visualization