Matplotlib动画无法正常工作

时间:2018-08-21 05:32:08

标签: python animation matplotlib

我正在使用python和MovieWriter中的matplotlib对球的路径进行动画处理,以逐帧对路径进行动画处理。我希望球的路径在100帧的过程中画出线,以使最终结果看起来像金色(我的动画只处理的线)第in this image行。但是,我最终在动画mp4视频中出现了一条不规则的偏移线。我无法发布视频,但快照类似于this。这条线使图的末端远离原点,但未形成第一幅图中所描绘的连贯线。我究竟做错了什么?我的代码在下面

FFMpegWriter = manimation.writers['ffmpeg']
metadata = dict(title='Movie Test', artist='Matplotlib',
                    comment='Movie support!')
writer = FFMpegWriter(fps=15, metadata=metadata)

import glob

#plt figure
fig = plt.figure()

#get specific file with data
fn = glob.glob(r"C:\Users\Admin\Desktop\STATS_basketball_tracking\anon\train\specificfile")

#plot image of the court
img = plt.imread(r"C:\Users\Admin\Pictures\Capture4.png ")
plt.imshow(img, zorder=0, extent=[0, 47, 0, 50])



tups = bball.stats_basketball.read_tuples(fn) 
positions = bball.stats_basketball.get_positions(tups)
goals = bball.stats_basketball.get_goals(tups)
ball = positions[0]

#initial x and y coordinate (col 0= x-coordinates col 1= y-coordinates)
x0 = ball[0,0]
y0 = ball[0,1]
lball, = plt.plot([x0], [y0], color="goldenrod")
     
with writer.saving(fig, "writer_test.mp4", 100):
    for i in range(100):
        for row in ball[:,0]:
            for row1 in ball[:,1]:
                x0 = [int(row),0]
                y0 = [int(row1),1]
                lball.set_data(x0, y0)
                fig.canvas.draw()
                writer.grab_frame()

0 个答案:

没有答案