Reputation: 724
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?
Upvotes: 4
Views: 1636
Reputation: 8277
You cannot set the bitrate through anim.to_html5_video()
but you can if exporting to disk with anim.save(bitrate=1024)
.
For a high resolution embedded video use:
HTML(anim.to_jshtml())
Upvotes: 3