Multiple time scales in animation using Python

Viewed 27

I want to show arrays b1 and b2 using animation. Basically, I want the elements of array b1 to appear all together say, at t=0 and then elements of array b2 all together at a later time, say at t=0.001. How do I implement two different time scales here?

import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
from celluloid import Camera

a = np.array([[0.04, 0.55, 0.16, 0.39, 0.51],
       [0.23, 0.85, 0.73, 0.53, 0.11],
       [0.43, 0.26, 0.1 , 0.06, 0.88],
       [0.95, 0.27, 0.61, 0.  , 0.17],
       [0.01, 0.72, 0.87, 0.14, 0.06]])

b1 = np.array([0.04, 0.23, 0.43])
b2 = np.array([0.26, 0.1, 0.06, 0.0, 0.17, 0.06, 0.14, 0.27])

fig, (ax1, cbar_ax) = plt.subplots(ncols=2, gridspec_kw={'width_ratios': [20, 2]},
                                   figsize=(25,25))
camera = Camera(fig)
sns.set_style('white')
sns.set(font_scale=3)
cbar_ax.tick_params(labelsize=50)
rectangles = []
for bb in b1.flatten():
    sns.heatmap(a, linewidth=2, ax=ax1, annot=True, cbar_ax=cbar_ax)
    rectangles.append(plt.Rectangle((np.where(a == bb)[1][0], np.where(a == bb)[0][0]), 1,1,
                                    fc='green', ec='green', lw=5, clip_on=False))
    for rect in rectangles:
        ax1.add_patch(rect)
        
        for bb in b2.flatten():
            sns.heatmap(a, linewidth=2, ax=ax1, annot=True, cbar_ax=cbar_ax)
            rectangles.append(plt.Rectangle((np.where(a == bb)[1][0], np.where(a == bb)[0][0]), 1,1                                            fc='green', ec='green', lw=5, clip_on=False))
            
                for rect in rectangles:
                ax1.add_patch(rect)
    camera.snap()

animation = camera.animate(interval=800)
animation.save('Today_5x5_CP.gif')
plt.show()
0 Answers
Related