'Getting rid of time lag in animation using Python
This code generates an animation using data set b on a matrix a. However, there is a time lag on how these values appear. I want the values of b to appear all together i.e. no time lag whatsoever. I tried to reduce the time interval to 1e-20 but still there's a visible lag.
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
from celluloid import Camera
a = np.array([[0.77619895, 0.479028 , 0.07942242, 2.07133691, 7.60581783],
[2.13382399, 0.58715807, 2.00747824, 0.48842203, 1.17064478],
[1.96443702, 4.19886806, 0.68915071, 0.17770271, 0.47118552],
[0.87647195, 0.18112885, 0.30398434, 0.46239019, 1.17481443],
[2.80282535, 0.53706217, 1.21285428, 2.83677513, 3.04105655]])
b = np.array([[0.77619895, 0.479028, 0.07942242, 2.07133691, 0.48842203, 2.00747824, 0.58715807, 2.13382399, 1.96443702, 0.87647195, 0.18112885, 0.30398434, 0.46239019, 1.17481443, 0.47118552, 0.17770271, 0.68915071, 1.17064478, 3.04105655, 2.83677513, 1.21285428, 0.53706217, 2.80282535]])
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 b.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=1e-20)
animation.save('5x5_Pcap_4.gif')
plt.show()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

