Animated Figure to video

Hello everyone,

I am trying to animate a video of a figure of two subplots, but I was not able to do it.

I have two lists of lists of the same size, which I want to use to create figures of two subplots by iterating through the lists.

This is my figure:

fig = plt.figure()
ax1 = fig.add_subplot(2, 1, 1)
ax2 = fig.add_subplot(2, 1, 2)

Here are my subplots:

ax1.imshow(list_1[i].reshape(5, 20), interpolation=None)
ax2.imshow(list_2[i].reshape(5, 20), interpolation=None)

What I now need is a way of animating a video by looping through my lists and rendering a video.

I tried FuncAnimation and ArtistAnimation, but was not able to do it. :disappointed_relieved:
Is there a way of solving my task. And if so, what is the best approach to do it?

Thank you very much for your time.

hi, can you please post an example of the FuncAnimation or ArtistAnimation code you tried? generally, the way to update an imshow is something like:

im1 = ax.imshow(list_1[0])
def animate(i):
      im1.set_data(list_1[i])

Thank you very much. I am now doing it this way, but I found a strange behaviour:

If list[0] contains only zeros and the following list elements contain random numbers, the animation will only show zeros.

If list[0] contains only 100s and the following list elements contain random numbers, the animation will only show 100s.

If list[0] contains only 0s and 1s, and the following list elements contain random numbers, the animation will only show 0s and 1s.

Somehow with im1 = ax1.imshow(list1[0], interpolation=None, animated=True) the plot is initialized and does not take any other value. I just don’t know haow to solve this issue.

Can you please post your code? It’s almost impossible to debug without knowing what you’re doing. Sample data is fine - a random array the same shape as your data or smaller.