Maybe you can help me. I'm trying to animate some bars together with a plot in matplotlib. For example, here's some code (only the bars) which is working fine:
from matplotlib import pyplot as plt
from matplotlib.animation import ArtistAnimation
import numpy as np
fig = plt.figure()
x = [1,2,3,4,5]
y = [5,7,2,5,3]
y_steps = []
for i in range(len(y)):
y_steps.append(np.linspace(0, y[i], 50))
data = []
for i in range(len(y_steps[0])):
data.append([y_steps[j][i] for j in range(len(y))])
ims = []
for i in range(len(y_steps[0])):
pic = plt.bar(x, data[i], color='c')
ims.append(pic)
anim = ArtistAnimation(fig, ims, interval=40)
plt.show()
But now I want some lines to grow together with the bars. I've tried a lot and googled a lot, but I am not able to make it work. For your understandig, I'm pasting my idea (of the not-working-code) here:
from matplotlib import pyplot as plt
from matplotlib.animation import ArtistAnimation
import numpy as np
fig = plt.figure()
x = [1,2,3,4,5]
y = [5,7,2,5,3]
y_steps = []
for i in range(len(y)):
y_steps.append(np.linspace(0, y[i], 50))
data = []
for i in range(len(y_steps[0])):
data.append([y_steps[j][i] for j in range(len(y))])
ims = []
for i in range(len(y_steps[0])):
pic_1 = plt.bar(x, data[i], color='c')
pic_2 = plt.plot(x, data[i], color='r')
ims.append([pic_1, pic_2])
anim = ArtistAnimation(fig, ims, interval=40)
plt.show()
It looks like all the pictures, saved in ims, are shown at once and there's no animation.
Maybe someone of you can help me. Thanks a lot.