更改Matplotlib动画中点的颜色

时间:2018-08-30 08:06:33

标签: python animation matplotlib

我用以下输出编写了matplotlib动画: animation

但是我想将移动点的颜色从粗体更改为浅色,以使移动点看起来像是在移动的陨石!实际上,我的目标是追踪粒子的路径。

这是我的脚本:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from scipy.interpolate import interp1d

x = np.array([ 0.18709292, -0.18420598,  0.71576185, -0.04572814, -0.61723946,
    0.4808109 ,  0.109512  ,  1.00947982,  0.24798984, -0.32352149,
    0.56144441,  0.19014551,  1.09011333,  0.32862335, -0.24288798,
    0.39250378,  0.02120488,  0.9211727 ,  0.15968272, -0.41182861,
    0.08292658, -0.28837232,  0.6115955 , -0.14989448, -0.72140581])

y = np.array([ 1.21200281,  0.39638079, -0.38601506,  0.0398137 ,  0.59113315,
    1.11611283,  0.30049081, -0.48190504, -0.05607628,  0.49524317,
    0.0593178 , -0.75630422, -1.53870008, -1.11287132, -0.56155186,
    0.64268579, -0.17293623, -0.95533209, -0.52950332,  0.02181613,
    1.58083678,  0.76521476, -0.0171811 ,  0.40864766,  0.95996712])

xnew = np.linspace(x.min(), x.max(), 100)
f = interp1d(x, y, kind=2)
ynew = f(xnew)

fig, ax = plt.subplots()
ax.axis([-3, 3, -3, 3])

l, = ax.plot([],[], 'bo')
ax.plot(x[7], y[7], 'ro')

def animate(i):
    l.set_data(xnew[i-5:i], ynew[i-5:i])
    return l,

ani = animation.FuncAnimation(fig, animate, np.arange(300), interval=40, repeat=True)
mywriter = animation.FFMpegWriter()
ani.save("output.gif")

0 个答案:

没有答案