# Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

# PythonAnimated heatmap with Seaborn and matplotlib

#### Axel

##### New Coder
Hello everyone !

I’m trying to animate a heatmap for data visualization.
(Just to clarify, I am a beginner in coding)

The heatmap is generated from a matrix where cells situated at the center of the map take a +1 value at each iteration. I don’t use numpy for the matrix but comprehension list. Heatmaps are generated with Seaborn module.

The heatmap is generated correctly and the matrix values change well. However, the animation does not start. I get a frozen image as if I had only generated a heat map without animation.

Here is the code :

import seaborn as sns
import matplotlib.pyplot as plt
from matplotlib import animation
#Definition of the initial matrix
def random_bed(p, n):
… states=[[0]*n for _ in range(n)]
… A=[(3,3),(3,4),(3,5),(3,6),(4,3),(4,4),(4,5),(4,6),(5,3),(5,4),(5,5),(5,6),(6,3),(6,4),(6,5),(6,6)]
… for (i,j) in A:
… states[j]=1
… return states
p=1
n=10
states=random_bed(p, n)
#function which aims to animate the matrix and increase the values of the center
def animate(i):
… data = states
… A=[(3,3),(3,4),(3,5),(3,6),(4,3),(4,4),(4,5),(4,6),(5,3),(5,4),(5,5),(5,6),(6,3),(6,4),(6,5),(6,6)]
… for (i,j) in A:
… states[j]=states[j]+1
… return states
… sns.heatmap(data, vmax=100)
fig = plt.figure()
sns.heatmap(states)
anim = animation.FuncAnimation(fig, animate, frames=20, repeat=False)
plt.show()

Here is an example of the output (with no animation):

After many unsuccessful attempts I really can't find the solution..

Does anyone have an idea of my mistake?

Thank you very much for taking the time to read me.
Have a great day !

Axel MEYER