0

I have an issue regarding saving animations in matplotlib. In the middle of the process, this error emerges:

anim.save(adress, writer=writervideo)
File "C:\\Users\\Shayan\\anaconda3\\lib\\site-packages\\matplotlib\\animation.py", line 1085, in save
writer.grab_frame(\*\*savefig_kwargs)
File "C:\\Users\\Shayan\\anaconda3\\lib\\site-packages\\matplotlib\\animation.py", line 357, in grab_frame
self.fig.savefig(self.\_proc.stdin, format=self.frame_format,
File "C:\\Users\\Shayan\\anaconda3\\lib\\site-packages\\matplotlib\\figure.py", line 3274, in savefig
self.canvas.print_figure(fname, \*\*kwargs)
File "C:\\Users\\Shayan\\anaconda3\\lib\\site-packages\\matplotlib\\backends\\backend_qtagg.py", line 81, in print_figure
super().print_figure(\*args, \*\*kwargs)
File "C:\\Users\\Shayan\\anaconda3\\lib\\site-packages\\matplotlib\\backend_bases.py", line 2338, in print_figure
result = print_method(
File "C:\\Users\\Shayan\\anaconda3\\lib\\site-packages\\matplotlib\\backend_bases.py", line 2204, in \<lambda\>
print_method = functools.wraps(meth)(lambda \*args, \*\*kwargs: meth(
File "C:\\Users\\Shayan\\anaconda3\\lib\\site-packages\\matplotlib_api\\deprecation.py", line 410, in wrapper
return func(\*inner_args, \*\*inner_kwargs)
File "C:\\Users\\Shayan\\anaconda3\\lib\\site-packages\\matplotlib\\backends\\backend_agg.py", line 454, in print_raw
fh.write(renderer.buffer_rgba())
OSError: \[Errno 22\] Invalid argument

The code work in a loop and this happens in the middle of processing and each time in a different step. The last lines of my code are:

anim = animation.FuncAnimation(fig=fig, func=update, interval=interval, frames=frame_range)
    writervideo = animation.FFMpegWriter(fps=60)
    adress = f"Animations/{record_id}.mp4"
    anim.save(adress, writer=writervideo)
    plt.close()

I have tried changing the fps but the issue still exists. I have also checked my code for any argument issues but everything is ok (at list seems ok). When I reduce the number of frames the code works and I thought maybe it is a buffer issue; but I am not sure.

Any help would be highly appreciated.

Regards.

0 Answers0