【发布时间】:2017-04-26 17:51:35
【问题描述】:
我生成一个图像序列,用 matplotlib 将其转换为电影。然后,这部电影显示在 jupyter notebook 中。问题是 jupyter notebook 中显示的电影的分辨率相当差。我的代码如下所示:
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())
我在 matplotlib.animation.FuncAnimation() 或 matplotlib.animation.to_html5_video() 中没有找到任何可以改变比特率或动画内容的选项。有什么办法可以提高分辨率吗?
【问题讨论】:
-
如果你只想展示动画,可以使用
%matplotlib notebook后端直接展示动画,无需导出到html5-video。 -
哦,不知道..这个很方便!
标签: python matplotlib jupyter-notebook