The following code supposed to do the same thing here where lines colours are updated during an animation. However, the colour is not being updated. Which part of this code is wrong?
import numpy as np
from matplotlib import pyplot as plt
from matplotlib.collections import LineCollection
import matplotlib.animation as animation
lines = []
for i in range(10):
for j in range(10):
lines.append([(0, i), (1, j)])
fig, ax = plt.subplots()
colors = np.random.random(len(lines))
col = LineCollection(lines, array=colors, cmap=plt.cm.gray)
ax.add_collection(col)
ax.autoscale()
ims = []
for i in range(100):
colors = np.random.random(len(lines))
col.set_array(colors)
ims.append([ax.add_collection(col)])
ani = animation.ArtistAnimation(fig, ims, interval=200, blit=True,repeat_delay=10000)
plt.show()
The output I get from the above code is below