在python matplotlib

时间:2016-07-26 23:11:06

标签: python matplotlib

我有一系列图像,我想逐个显示它们,并允许用户使用matplotlib中的下一个和上一个按钮在图像之间导航。 这是我的代码:

fig, ax = plt.subplots()


class Index(object):
   ind = 0

   def next(self, event):
    self.ind += 1
    print self.ind
    orig_frame = cv2.imread(FFMPEG_PATH + all_frames[self.ind])
    ax.imshow(orig_frame)


   def prev(self, event):
    self.ind -= 1
    orig_frame = cv2.imread(FFMPEG_PATH + all_frames[self.ind])
    ax.imshow(orig_frame)


callback = Index()
axnext = plt.axes([0.8, 0.7, 0.1, 0.075])
axprev = plt.axes([0.8, 0.6, 0.1, 0.075])
next_button = Button(axnext, 'Next')
next_button.on_clicked(callback.next)
prev_button = Button(axprev, 'Previous')
prev_button.on_clicked(callback.prev)


plt.show()
plt.waitforbuttonpress()

问题是,只要我点击下一个按钮,它就不会显示任何内容,程序会立即终止。我该怎么办?

0 个答案:

没有答案