def image_stack_to_movie(images, frames=None, vmin=None, vmax=None,
figsize=(6, 5), cmap='CMRmap', fps=10):
"""Convert image stack to movie and show in notebook.
Parameters
----------
images : array_like
Stack of images to show as a movie of shape (N, y, x).
frames : int
Number of frames to process
vmin : number
Minimum value to display for ``imshow``
vmax : number
Maximum value to display for ``imshow``
figsize : tuple
Figure size for each frame
cmap : string
Colormap to use for plotting image
fps : int
Framerate for created movie
"""
if frames is None:
frames = images.shape[0]
fig = plt.figure(figsize=figsize)
ax = fig.add_subplot(111)
im = plt.imshow(images[1], vmin=vmin, vmax=vmax, cmap=cmap,
interpolation='none')
cbar = fig.colorbar(im)
cbar.ax.tick_params(labelsize=14)
cbar.set_label(r"Intensity [ADU]", size=14,)
for item in ([ax.xaxis.label, ax.yaxis.label] +
ax.get_xticklabels() + ax.get_yticklabels()):
item.set_fontsize(14)
item.set_fontweight('bold')
def animate(i):
im.set_array(images[i])
ax.set_title('Frame {}'.format(i), fontsize=16, fontweight='bold')
return im,
anim = animation.FuncAnimation(fig, animate, frames=frames,
interval=1, blit=True)
plt.close(anim._fig)
# return anim.to_html5_video()
return HTML(_anim_to_html(anim, fps))
评论列表
文章目录