gpt4 book ai didi

python - Matplotlib 动画

转载 作者:行者123 更新时间:2023-12-04 08:44:03 26 4
gpt4 key购买 nike

我正在尝试创建一个 ABC Logo 并使用 matplotlib 对其进行动画处理,我通过更改增量索引获得了所有阶段我能够获得所有 x 和 y 坐标但我无法从一个阶段动画到另一个阶段。下面是我正在尝试做的事情的链接。
https://www.youtube.com/watch?v=sL0FhqGtV4U&ab_channel=AustralianTelevisionArchive

import matplotlib.pyplot as plt
import matplotlib.animation as animation
import math
import numpy as np
from matplotlib.animation import FuncAnimation


fig = plt.figure()
axis = plt.axes(xlim =(-110, 110),
ylim =(-110, 110))
delta = [0, 3.14 / 8, 3.14 / 4, 3 * 3.14 / 8, 3.14 / 2, 5 * 3.14 / 8, 3 * 3.14 / 8, 7 * 3.14 / 8, 3.14]

def dS(delta):
A = 100
B = 100
a = 1
b = 3
# delta = 3.14/4
t = 0
sinVals = []
cosVals = []
for i in range(0, 1000):
t += 0.01
# Apply Lissajous Parametric Equations
sinVals.append(A * math.sin(a * t + delta))
cosVals.append(B * math.sin(b * t))
return sinVals,cosVals

sinVals,cosVals=deltaShift.dS(delta[1])


line, = axis.plot(sinVals, cosVals)
plt.show()

最佳答案

这将产生你想要的

import matplotlib.pyplot as plt
import matplotlib.animation as animation
import numpy as np
from matplotlib.animation import FuncAnimation


pi = np.pi
deltas = np.linspace(0,8,32) / pi

def dS(delta):

A = 100
B = 100
a = 1
b = 3
# delta = 3.14/4
t = 0
sinVals = []
cosVals = []
for i in range(0, 1000):
t += 0.01
# Apply Lissajous Parametric Equations
sinVals.append(A * math.sin(a * t + delta))
cosVals.append(B * math.sin(b * t))
return sinVals,cosVals

def make_plot(delta):

ax.clear()
ax.set_xlim(-110, 110)
ax.set_ylim(-110, 110)
sinVals,cosVals=dS(delta)
line, = ax.plot(sinVals, cosVals)

fig,ax = plt.subplots()

ani = animation.FuncAnimation(fig, make_plot, deltas, blit = False)
ani.save('test.gif', writer='pillow', fps=16)
输出 gif 文件是
gif

关于python - Matplotlib 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64421567/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com