[Python] Set matplotlib video animation size (1920x1080)

Discussão em 'Python' iniciado por Stack, Agosto 23, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to create a matplotlib animation that is 1920x1080. The following animation generated is (1152x648), which is the right ratio but too small. I know that I can do this after the fact with ffmpeg, but I'd like to avoid re-encoding if possible.

    y = my_data
    fig = plt.figure(figsize=(16,9))

    def ani(i):
    # Animation Code

    animator = FuncAnimation(fig, ani, frames=y.shape[0])

    # Can't figure out what extra_args to set here
    ffmpeg_writer = FFMpegWriter(fps=y.shape[0]/sound.duration_seconds, extra_args=['-scale', '1920x1080'])
    animator.save('mymovie.mp4', writer=ffmpeg_writer)

    print(ffmpeg_writer.frame_size) # prints (1152, 648)

    ipd.Video('mymovie.mp4')


    As you can see above, I have tried a few extra_args, however I can't get anything to work.

    Continue reading...

Compartilhe esta Página