-
-
Save louispotok/c28cc75746de8534a75ad4ab4b868165 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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