代码:
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.animation as animation
if __name__=="__main__":
fig = plt.figure()
ax = Axes3D(fig,auto_add_to_figure=False)
fig.add_axes(ax)
ax.legend(loc="best",labels="xxx")
ax.axis('off')
def demo(num):
a=num
return create_img(a,fig,ax)
print(1)
ani = animation.FuncAnimation(fig, demo,fargs=[],
interval=tnums)
ani.save('test.gif')
fig.show()
注:create_img将操作后的ax作为返回值。
结果:
1
MovieWriter stderr:
[AVFilterGraph @ 0000000002af6f00] No such filter: 'palettegen'
Error configuring filters.
Traceback (most recent call last):
File "C:\Users\86158\AppData\Roaming\Python\Python39\site-packages\matplotlib\animation.py", line 236, in saving
yield self
File "C:\Users\86158\AppData\Roaming\Python\Python39\site-packages\matplotlib\animation.py", line 1177, in save
writer.grab_frame(**savefig_kwargs)
File "C:\Users\86158\AppData\Roaming\Python\Python39\site-packages\matplotlib\animation.py", line 356, in grab_frame
self.fig.savefig(self._proc.stdin, format=self.frame_format,
File "C:\Users\86158\AppData\Roaming\Python\Python39\site-packages\matplotlib\figure.py", line 3005, in savefig
self.canvas.print_figure(fname, **kwargs)
File "C:\Users\86158\AppData\Roaming\Python\Python39\site-packages\matplotlib\backend_bases.py", line 2255, in print_figure
result = print_method(
File "C:\Users\86158\AppData\Roaming\Python\Python39\site-packages\matplotlib\backend_bases.py", line 1669, in wrapper
return func(*args, **kwargs)
File "C:\Users\86158\AppData\Roaming\Python\Python39\site-packages\matplotlib\backends\backend_agg.py", line 455, in print_raw
fh.write(renderer.buffer_rgba())
OSError: [Errno 22] Invalid argument
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\86158\Desktop\MEME\MathmaticGraphic\3DGraphic.py", line 905, in <module>
Graphic_main("sin(x)=y\nz=t\ncos(y)=z",modefunc=write()._write_t_x,tnums=10,nums=10)
File "C:\Users\86158\Desktop\MEME\MathmaticGraphic\3DGraphic.py", line 896, in Graphic_main
ani.save('test.gif')
File "C:\Users\86158\AppData\Roaming\Python\Python39\site-packages\matplotlib\animation.py", line 1177, in save
writer.grab_frame(**savefig_kwargs)
File "C:\Users\86158\AppData\Local\Programs\Python\Python39\lib\contextlib.py", line 135, in __exit__
self.gen.throw(type, value, traceback)
File "C:\Users\86158\AppData\Roaming\Python\Python39\site-packages\matplotlib\animation.py", line 238, in saving
self.finish()
File "C:\Users\86158\AppData\Roaming\Python\Python39\site-packages\matplotlib\animation.py", line 347, in finish
self._cleanup() # Inline _cleanup() once cleanup() is removed.
File "C:\Users\86158\AppData\Roaming\Python\Python39\site-packages\matplotlib\animation.py", line 378, in _cleanup
raise subprocess.CalledProcessError(
subprocess.CalledProcessError: Command '['ffmpeg', '-f', 'rawvideo', '-vcodec', 'rawvideo', '-s', '640x480', '-pix_fmt', 'rgba', '-r', '100.0', '-loglevel', 'error', '-i', 'pipe:', '-filter_complex', 'split [a][b];[a] palettegen [p];[b][p] paletteuse', '-y', 'test.gif']' returned non-zero exit status 1.
为什么?求解决