Nanocartography: Planning for success in analytical electron microscopy

Montage Movie

Article - Nanocartography Data - Collaborative Analysis Movie Interactivity - movie buttons.

# Widget for displaying movie animations.

%matplotlib widget

import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
from mpl_toolkits.axes_grid1 import make_axes_locatable
from IPython.display import HTML
import numpy as np
import imageio as iio
from PIL import Image
import matplotlib

#For big animations
matplotlib.rcParams['animation.embed_limit'] = 2**128

dpi = 70
plot_every_frame = 6
width = 700
movie_name = "data/Montage.mp4"

plt.ioff()
fig, axs = plt.subplots(1, figsize=(width/dpi, width/dpi), dpi=dpi)


#Movie
axs.axis('off')
vid = iio.get_reader(movie_name)
num_frames = vid.count_frames()
array = vid.get_data(0)
array = array[:,:,:] # grayscale
im=axs.imshow(array)

def display_frame(index):
    array = vid.get_data(index*plot_every_frame)[:,:,:]
    #array = 255 - array # reverse
    im.set_data(array)
    fig.canvas.draw_idle()

    return None
    
animation = FuncAnimation(
    fig,
    display_frame,
    frames=num_frames//plot_every_frame,
    repeat=False,
    blit=False,
    interval=100,
)

HTML(animation.to_jshtml())