简体   繁体   中英

The resolution of an animation with matplotlib on jupyter notebook?

I generate an image sequence, convert it to a movie with matplotlib. Then, this movie is shown in jupyter notebook. The problem is that the resolution of the movie shown in jupyter notebook is rather poor. My code looks like this:

import numpy as np
import tifffile
import matplotlib.pyplot as plt
from matplotlib import animation
from Ipython.display import HTML
stack = tifffile.imread("some image stack")
fig, ax = plt.subplots()
ax.set_axis_off()
im = ax.imshow(stack[:, :, 0])

def init():
    im.set_data(stack[:, :, 0])
    return [im]

def animate(i):
    im.set_array(stack[:, :, i])
    return [im]

anim = animation.FuncAnimation(fig, animate, init_func=init,
                               frames=stack.shape[2], interval=1000, blit=True)

HTML(anim.to_html5_video())

I did not find any options in matplotlib.animation.FuncAnimation() or in matplotlib.animation.to_html5_video() that can change the bitrate or something of the animation. Is there any way to increase the resolution?

You cannot set the bitrate through anim.to_html5_video() but you can if exporting to disk with anim.save(bitrate=1024) .

See https://matplotlib.org/3.1.0/api/_as_gen/matplotlib.animation.Animation.html#matplotlib.animation.Animation.save

For a high resolution embedded video use:

HTML(anim.to_jshtml())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM