我正在用python中的matplotlib和MovieWriter一帧一帧地为球的路径设置动画。我希望球的路径在100帧的过程中画出它的线,因为最终的结果看起来像金色的(我的动画处理的唯一的线)线。然而,我最终得到一个不规则的移动线在我的动画mp4视频。我不能发布视频,但它的快照看起来像。这条线将端点从绘图周围的原点移开,但不会形成第一个图像中描述的连贯线。我做错什么了?我的代码在下面
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()
目前没有回答
相关问题 更多 >
编程相关推荐