Skip to content

Instantly share code, notes, and snippets.

@sabopy
Created October 1, 2020 11:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sabopy/6a617c1aef3abbc4c4658aeebde2e268 to your computer and use it in GitHub Desktop.
Save sabopy/6a617c1aef3abbc4c4658aeebde2e268 to your computer and use it in GitHub Desktop.
import numpy as np
import matplotlib.pyplot as plt
from scipy import ndimage
import matplotlib.animation as animation
from IPython.display import HTML
from mpl_toolkits.axes_grid1 import make_axes_locatable
cmaps = ['turbo','viridis', 'plasma', 'inferno', 'magma', 'cividis','Greys', 'Purples',
'Blues', 'Greens', 'Oranges', 'Reds','YlOrBr', 'YlOrRd', 'OrRd', 'PuRd', 'RdPu',
'BuPu','GnBu', 'PuBu', 'YlGnBu', 'PuBuGn', 'BuGn', 'YlGn','binary', 'gist_yarg',
'gist_gray', 'gray', 'bone', 'pink','spring', 'summer', 'autumn', 'winter', 'cool',
'Wistia','hot', 'afmhot', 'gist_heat', 'copper', 'PiYG', 'PRGn', 'BrBG', 'PuOr', 'RdGy', 'RdBu',
'RdYlBu', 'RdYlGn', 'Spectral', 'coolwarm', 'bwr', 'seismic','twilight', 'twilight_shifted',
'hsv','Pastel1','Pastel2', 'Paired', 'Accent','Dark2', 'Set1', 'Set2', 'Set3','tab10', 'tab20', 'tab20b',
'tab20c','flag', 'prism', 'ocean', 'gist_earth', 'terrain', 'gist_stern','gnuplot', 'gnuplot2',
'CMRmap', 'cubehelix', 'brg','gist_rainbow', 'rainbow', 'jet', 'nipy_spectral', 'gist_ncar']
#make data
n = 6
s = 512
im = np.zeros((s, s))
points = (s*np.random.random((2, n**2))).astype(int)
im[points[0], points[1]] = 10**5
points = (s*np.random.random((2, n**2))).astype(int)
im[points[0], points[1]] = -10**5
im = ndimage.gaussian_filter(im, sigma=s/(5.*n))
#animation
fig, ax = plt.subplots(figsize=(8,8))
img = ax.imshow(im,interpolation="None")
divider = make_axes_locatable(ax)
cax = divider.append_axes("right", size="5%", pad=0.02)
plt.colorbar(img, cax=cax)
ax.axis("off")
def update(i):
img.set_cmap(cmaps[i])
ax.set_title(cmaps[i],fontsize=30)
return fig,
ani = animation.FuncAnimation(fig, update, len(cmaps),interval=250)
ani.save('cmapanim.mp4', writer="ffmpeg",dpi=100)
HTML(ani.to_html5_video())
#version
import scipy
print(scipy.__version__)
1.5.2
print(np.__version__)
1.19.1
import matplotlib
print(matplotlib.__version__)
3.3.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment