Python Forum
cannot create animation on 2D array using Matplotlib and FuncAnimation
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
cannot create animation on 2D array using Matplotlib and FuncAnimation
#1
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.
Reply
#2
No solution found (Up !)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Matplotlib FuncAnimation NewPi 3 1,268 Dec-30-2022, 11:14 PM
Last Post: NewPi
  How do you create a scatterplot of dataframe using matplotlib? asdad 2 855 Dec-07-2022, 04:53 PM
Last Post: Larz60+
  Create array of values from 2 variables paulo79 1 1,078 Apr-19-2022, 08:28 PM
Last Post: deanhystad
  Matplotlib Animation with Threading peterjv26 4 7,136 Oct-08-2021, 05:51 PM
Last Post: peterjv26
  Matplotlib: How do I convert Dates from Excel to use in Matplotlib JaneTan 1 3,203 Mar-11-2021, 10:52 AM
Last Post: buran
  Python Matplotlib: How do I save (in pdf) all the graphs I create in a loop? JaneTan 1 8,834 Feb-28-2021, 06:20 PM
Last Post: Larz60+
  Python Matplotlib: Create chart for every 4 columns in Excel file JaneTan 2 2,755 Feb-28-2021, 05:02 AM
Last Post: JaneTan
  Create array from string steve87bg 4 3,162 Jul-13-2020, 07:55 PM
Last Post: jefsummers
  create an array of each line of text macieju1974 7 3,386 Jun-07-2020, 06:30 PM
Last Post: Yoriz
  Attribute Error - trying to create a pixel array out of PNG files The_Sarco 1 1,999 Apr-29-2020, 07:10 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020