I want to have several subplots, two of which showing frames from a video feed, and a third showing computed results as a bar graph.
After creating a matplotlib figure, I create several subplot2grids, which I then update with FuncAnimation.
The usual way I would create a bar graph (to be updated) is:
fig = plt.figure()
ax = plt.axes(xlim=(0, 9), ylim=(0, 100))
rects = plt.bar(res_x, res_y, color='b')
def animate(args):
...
...
for rect, yi in zip(rects, results):
rect.set_height(yi*100)
return rects
anim = animation.FuncAnimation(fig, animate, frames=200, interval=20, blit=True)
plt.show()
I am now trying to add a bar graph along side the other subplots:
fig = plt.figure()
plt1 = plt.subplot2grid((2, 2), (0, 0), rowspan=2)
plt2 = plt.subplot2grid((2, 2), (0, 1))
#Confusion with the following
bar_plot = plt.subplot2grid((2,2), (1,1))
ax = plt.axes(xlim=(0, 9), ylim=(0, 100))
rects = plt.bar(res_x, res_y, color='b')
def animate(args):
...
...
im1 = plt1.imshow(...)
im2 = plt2.imshow(...)
for rect, yi in zip(rects, results):
rect.set_height(yi*100)
return im1, im2, rects
anim = animation.FuncAnimation(fig, animate, frames=200, interval=20, blit=True)
plt.show()
I get the following error: AttributeError: 'BarContainer' object has no attribute 'set_animated'
Any ideas how I can "place" a bar graph as a subplot, and have it update together with other data from subplots?
Thanks!
See Question&Answers more detail:
os