Skip to content

Commit

Permalink
adds play function to chart for animating a stack of images
Browse files Browse the repository at this point in the history
  • Loading branch information
Niru Maheswaranathan committed Feb 19, 2016
1 parent f782141 commit 81cf780
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion jetpack/chart.py
Expand Up @@ -9,10 +9,11 @@
# imports
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from functools import wraps

__all__ = ['plotwrapper', 'image', 'hist', 'hist2d', 'errorplot', 'random_slice',
'setfontsize', 'noticks', 'nospines', 'breathe']
'setfontsize', 'noticks', 'nospines', 'breathe', 'play']


def plotwrapper(fun):
Expand Down Expand Up @@ -140,6 +141,33 @@ def image(data, mode='div', center=True, cmap=None, aspect='equal', vmin=None, v
plt.draw()


def play(images, cmap='viridis', interval=50, clim=None, **kwargs):

fig = plt.figure()
ax = fig.add_subplot(111)
noticks(ax=ax)

# set up the figure
plt.axis('equal')
img = ax.imshow(images[0])

# set up the colormap
img.set_cmap(cmap)
img.set_interpolation('nearest')
if clim is not None:
img.set_clim(clim)
else:
maxval = np.max(np.abs(images))
img.set_clim([-maxval, maxval])

def animate(im):
img.set_data(im)

anim = animation.FuncAnimation(fig, animate, images, interval=interval)
plt.show()
return anim


@plotwrapper
def corrplot(C, cmap=None, cmap_range=(0.0, 1.0), cbar=True, fontsize=14, **kwargs):
"""
Expand Down

0 comments on commit 81cf780

Please sign in to comment.