#!/usr/bin/env python3# Plot a PGN game using python-chess and ImageMagickimportosimportchess.pgnimportchess.svgpgn=open('deep_blue_kasparov_1996_1.pgn')game=chess.pgn.read_game(pgn)board=game.board()defsvg(i):lm=board.peek()a=[(lm.from_square,lm.to_square)]s=chess.svg.board(board,arrows=a,size=800)f1="g_%04u.svg"%if2="g_%04u.png"%iwithopen(f1,'w')asf:f.write(s)os.system("convert %s%s"%(f1,f2))os.system("rm %s"%f1)i=1formingame.mainline_moves():board.push(m)svg(i)i+=1# pause animation at the end:forjinrange(3):svg(i)i+=1# create animation with# convert -delay 150 g_*.png -loop 0 g.gif