cannot create animation on 2D array using Matplotlib and FuncAnimation - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: cannot create animation on 2D array using Matplotlib and FuncAnimation (/thread-31930.html) |
cannot create animation on 2D array using Matplotlib and FuncAnimation - Caffeine_Addict - Jan-10-2021 Hello, I'm trying to animate a 2D array, but it's not Working :( Here is my code : import numpy as np import matplotlib.pyplot as plt from matplotlib import cm, animation INDEXTABLE = 20 fig, ax = plt.subplots() i = 0 def updated(*args): global i if i < 99: i += 1 else: i = 0 img.set_data(alive(mat)) return img def alive(mat): #Some working stuff wo take a mat as parameter and return modified mat return mat mat = np.zeros((INDEXTABLE, INDEXTABLE)) #define a glider mat[10, 10] = 1 mat[11, 11] = 1 mat[12, 9] = 1 mat[12, 10] = 1 mat[12, 11] = 1 img = ax.imshow(mat, interpolation='None', cmap='viridis', aspect='equal') ani = animation.FuncAnimation(fig, updated, interval=50) plt.show()I tried many things to make it working : change set data to set array, add parameters att updated function ... but i cant find the right Solution Thanks for help guys ! Edit : i forgot to tell you something strange : when i put a breakpoint on my updated function, the function is never reached. RE: cannot create animation on 2D array using Matplotlib and FuncAnimation - Caffeine_Addict - Jan-12-2021 No solution found (Up !) |