In matplotlib, I can make a gif with “FuncAnimation” and export it with the method “to_jshtml()” that returns an HTML. The output adds a “scrubber” widget to the animation, which is great. Here is a reproducible example:
import xarray as xr
from matplotlib import pyplot as plt, animation
from IPython.display import HTML
ds = xr.tutorial.open_dataset('air_temperature')
tas=ds.air
tas = tas - 273.15
# Get a handle on the figure and the axes
fig, ax = plt.subplots(figsize=(12,6))
# Plot the initial frame.
cax = tas[0,:,:].plot(
add_colorbar=True,
cmap='coolwarm',
vmin=-40, vmax=40,
cbar_kwargs={
'extend':'neither'
}
)
# Next we need to create a function that updates the values for the colormesh, as well as the title.
def animate(frame):
cax.set_array(tas[frame,:,:].values.flatten())
ax.set_title("Time = " + str(tas.coords['time'].values[frame])[:13])
# Finally, we use the animation module to create the animation.
ani = animation.FuncAnimation(
fig, # figure
animate, # name of the function above
frames=40, # Could also be iterable or list
interval=200 # ms between frames
)
# Then
HTML(ani.to_jshtml())
I would like to do the same with bokeh, i.e. I want to make a gif with the “scrubber” widget and export it to HTML, but taking advantage of the bokeh customisation possibilities.
There is a way to do this?
I expected a Bokeh solution for this, Bokeh is more powerful tool.