Skip to content
Advertisement

Animation issue in Python

I want the green rectangle to not disappear as it moves from one value to another in matrix b. For example, the rectangle is around 0.24671953. Then the rectangle stays on this value. Then another rectangle appears onto the next value which is 0.25959473. Then another rectangle appears on 0.41092171, with the previous two rectangles not disappearing.

JavaScript

enter image description here

Advertisement

Answer

It looks like celluloid clears the existing plot at each snap. You can recreate the plot from scratch at each step. The rectangles can be stored in a list.

To avoid that new colorbar positions are set at each step, you can use sns.heatmap‘s cbar_ax= parameter to always use the same colorbar ax:

JavaScript

heatmap with rectangles animation

An alternative could be to directly use matplotlib’s animation framework. Then, the code could look like:

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