Nanocartography: Planning for success in analytical electron microscopy
Contents
Unknown Calculator 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
image_name = "data/UnknownCalculator_static.jpg"
movie_name = "data/UnknownCalculator.mp4"
plt.ioff()
fig, axs = plt.subplots(2, figsize=(width/dpi, width/dpi), dpi=dpi)
#Static plot
axs[0].axis('off')
im = Image.open(image_name)
im=axs[0].imshow(im)
#Movie
axs[1].axis('off')
vid = iio.get_reader(movie_name)
num_frames = vid.count_frames()
array = vid.get_data(0)
array = array[:,:,:] # grayscale
im=axs[1].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=50,
)
HTML(animation.to_jshtml())
<IPython.core.display.HTML object>