I tried to program something similar to what the person in this thread programed: Matplotlib Animation
His code does work for me very fine considering the proposed fix but when I tried to program something similar the animation somehow does not work in jupyter notebook for me. (If I download it as a .py it works fine) I think its very weird that it works as a .py but not in jupyter, especially considering that the code example in the link above also does work in jupyter notebook for me.
My code is the following: (of course there are functions missing which produce the variables "time
" and "inputs[b,t,x,y,z]")
%matplotlib notebook
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import numpy as np
def plot_fig():
global time, inputs
fig = plt.figure("Animation")
img = []
for i in range(time):
img.append([plt.imshow(inputs[1,i,:,:,0])])
anim = animation.ArtistAnimation(fig, img, interval = 25, blit=True, repeat_delay = 0)
plt.show()
Somehow I only get a static picture of inputs[1,0,:,:,0]
in jupyter notebook.
I do not get any errors.
Does anyone have an idea why?
Thanks for any help!
Edit: this code which creates random matrices does somehow work for me as well. Very weird considering the inputs matrix in the code above has the right dimensions and the right content.
%matplotlib notebook
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import numpy as np
time = 100
fig = plt.figure("Animation")
img = []
for i in range(time):
inputs = np.random.rand(10,10)
img.append([plt.imshow(inputs)])
anim = animation.ArtistAnimation(fig, img, interval = 25, blit=True, repeat_delay = 0)
plt.show()