我有一系列图像,我试图使用 matplotlib 中的图形/绘图来显示它们。此外,我希望允许用户通过单击我使用创建的按钮next
在图像之间导航。这是我的代码:previous
matplotlib.widgets
class Index(object):
ind = 0
def next(self, event):
self.ind += 1
orig_frame = cv2.imread(FFMPEG_PATH + all_frames[self.ind])
ax.imshow(orig_frame)
fig.canvas.draw()
plt.waitforbuttonpress()
def prev(self, event):
self.ind -= 1
if self.ind >= 0:
orig_frame = cv2.imread(FFMPEG_PATH + all_frames[self.ind])
ax.imshow(orig_frame)
fig.canvas.draw()
plt.waitforbuttonpress()
fig, ax = plt.subplots()
callback = Index()
start_frame = 0
orig_frame = cv2.imread(FFMPEG_PATH + all_frames[start_frame])
ax.imshow(orig_frame)
axnext = plt.axes([0.81, 0.05, 0.1, 0.075])
axprev = plt.axes([0.7, 0.05, 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()
问题是,虽然我已经把fig.canvas.draw()
and放在了and函数plt.waitforbuttonpress()
的末尾,但只要我点击按钮,程序就会终止。知道有什么问题吗?next
prev
next