【问题标题】:The resolution of an animation with matplotlib on jupyter notebook?jupyter notebook 上 matplotlib 动画的分辨率?
【发布时间】: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


【解决方案1】:

您无法通过anim.to_html5_video() 设置比特率,但如果使用anim.save(bitrate=1024) 导出到磁盘,则可以。

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

对于高分辨率嵌入式视频使用:

HTML(anim.to_jshtml())

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-05-25
    • 1970-01-01
    • 1970-01-01
    • 2018-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-07
    相关资源
    最近更新 更多