我使用的是https://matplotlib.org/3.1.0/gallery/event_handling/image_slices_viewer.html中略微更改的代码(更改了索引)
不幸的是,输出是静态图像。我使用的是jupyter notebook (在我的实际代码中类后的函数是缩进的)
class IndexTracker(object):
def __init__(self, ax, X):
self.ax = ax
ax.set_title('use scroll wheel to navigate images')
self.X = X
self.slices, rows, cols = X.shape
self.ind = self.slices//2
self.im = ax.imshow(self.X[self.ind, :, :])
self.update()
def onscroll(self, event):
print("%s %s" % (event.button, event.step))
if event.button == 'up':
self.ind = (self.ind + 1) % self.slices
else:
self.ind = (self.ind - 1) % self.slices
self.update()
def update(self):
self.im.set_data(self.X[self.ind, :, :])
self.ax.set_ylabel('slice %s' % self.ind)
self.im.axes.figure.canvas.draw()然后我是如何查看3D图像的
cube = dicom_cbct_view(test_dir, trim_factor=trim_factor)
fig, ax = plt.subplots(1, 1)
tracker = IndexTracker(ax, cube)
fig.canvas.mpl_connect('scroll_event', tracker.onscroll)
plt.show()输出(铁路超高滚动)

发布于 2019-12-31 11:24:47
抱歉,各位。我是个笨蛋。我需要
%matplotlib qt 所以下面的工作是有效的
%matplotlib qt
fig, ax = plt.subplots(1, 1)
tracker = IndexTracker(ax, cube)
fig.canvas.mpl_connect('scroll_event', tracker.onscroll)
plt.show()https://stackoverflow.com/questions/59539183
复制相似问题