【发布时间】:2017-09-08 16:47:20
【问题描述】:
我想要几个子图,其中两个显示来自视频源的帧,第三个显示计算结果作为条形图。 创建 matplotlib 图形后,我创建了几个 subplot2grids,然后使用 FuncAnimation 对其进行更新。
创建条形图(待更新)的常用方法是:
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()
我现在正在尝试在其他子图旁边添加一个条形图:
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()
我收到以下错误:AttributeError: 'BarContainer' object has no attribute 'set_animated'
有什么想法可以将条形图“放置”为子图,并与子图中的其他数据一起更新吗?
谢谢!
【问题讨论】:
标签: python matplotlib subplot