from matplotlib.widgets import Slider
import matplotlib.pyplot as plt
import numpy as np
def ddd(images):
def _update_image(num):
num = int(num)
image = np.squeeze(images[num:num+1])
img_ax.set_data(image)
fig.canvas.draw_idle()
if images.ndim is not 3:
raise ValueError("Not a 3D image.")
Z, _, _ = images.shape
fig, ax = plt.subplots()
img_ax = ax.imshow(np.squeeze(images[0]), cmap="gray")
ax.axis("off")
sliderax = plt.axes([0.19, 0.05, 0.65, 0.03],
facecolor="lightgoldenrodyellow")
img_slider = Slider(sliderax, "Z", 0, Z-1,
valfmt='%d', valinit=0)
img_slider.on_changed(_update_image)
plt.show()
I'd forgotten to include the import statements. Just in case you'd like to test the code. Input image of shape (Z, N, M).