0

I'm currently working on a lattice boltzmann simulation, and it is my first python project. While I managed to make a working simulation, I'm having trouble using Matplotlib FuncAnimation (I'm using spyder).

I have stored all the datas resulting from simulation in a numpy 2d array. This array has all the data points for time t stored as columns, and those same data for time t+dt are stored in the next column.

Of course a simulation generates lots of data (the small test i'm currently running simulate 37 points over 400 time iteration), hence why I want to create an animated plot to see how my data evolves over time. I, however, can't seem to manage to create a working animation using FuncAnimation from Matplotlib

The code i'm currently using to create my animation is this one:

fig, ax = plt.subplots()
plt.ylim([0,2])
line=ax.plot(h[:,0])
def update(num):
    line.set_xdata(h[:,num])
    return (line)
ani = animation.FuncAnimation(fig, update, frames=(np.size(h)), interval=20)
plt.show()

Please note that h is the 2d array I spoke of above. This code only returns a fix plot of the initial iteration of h, and I can't figure what's wrong in the code.

If someone spot the problem, some help would absolutely be welcome.

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
  • There are two possibilities: 1) Use `line, = ax.plot(h[:,0])`... because `ax.plot` returns a list... When you use `line,` you get the first line in the list... 2) But if you decided use `line = ax.plot(h[:,0])`, then use `line[0].set_xdata(h[:,num])` inside `update` and `return line`. – Joao_PS May 10 '23 at 14:56
  • Tip: Are you sure about `ylim` to all data? – Joao_PS May 10 '23 at 14:59

0 Answers0