Skip to content
Advertisement

Python Seaborn dynamic update of heatmap data

I would like to update dynamically a heatmap made with Seaborn, adding data line one by one. The sample code below get the basics work done, but instead of updating the heatmap it seems to nest a new one in the previous one.

Thank you in advance for any help/solution you may provide.

JavaScript

enter image description here

Advertisement

Answer

I re-structured your code in order to exploit matplotlib.animation.FuncAnimation.
In order to avoid drawing a new heatmap and a new colobar in each iteration, it is necessary to specify in which axis draw each of them through ax and cbar_ax parameters in seaborn.heatmap.
Moreover, after drawing an heatmap, it is convenient to erase the previous one with ax.cla().

Complete Code

JavaScript

enter image description here


If you want to keep your original code structure, you can apply the same principles:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement