Skip to content

Instantly share code, notes, and snippets.

@dobrych
Created December 20, 2016 14:46
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dobrych/bc9bfaf779eee576851c47ac6cfb8623 to your computer and use it in GitHub Desktop.
Save dobrych/bc9bfaf779eee576851c47ac6cfb8623 to your computer and use it in GitHub Desktop.
# create figure form matplotlib.pyplot
fig = plt.figure()
# make global min/max for the whole array,
# so colour scale will be consistent between the frames
data_min = np.nanmin(full_data_panel.values)
data_max = np.nanmax(full_data_panel.values)
# create iterator
data_frames_iterator = full_data_panel.iteritems()
def update_frame(i):
plt.clf()
key, heatmap_data = next(data_frames_iterator)
# make it latitude-sorted (top > bottom == north > south)
heatmap_data.sort_index(inplace=True, ascending=False)
# use seaborn for a little better looking heatmap (matplotlib-based)
ax = sns.heatmap(
heatmap_data,
annot=False,
vmin=data_min,
vmax=data_max,
cmap='jet',
linewidths=.5,
xticklabels=5,
yticklabels=10
)
# write animation frames
anim = FuncAnimation(fig, update_frame, frames=len(full_data_panel)-1, interval=500)
anim.save('test.gif', writer='imagemagick')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment