I am trying to create a function to display 3D images and synchronize them over the slices and orientation.I have a dropdown widget to select orientation but the slider must be linked to it to adapt its max value dynamically. How can you do that? I have the impression that once you're in the function the slice is only an integer, is there a way to modify slice.max
?
import matplotlib.pyplot as pltfrom ipywidgets import interact, fixed, widgetsimport numpy as npdef show(imageList, gridShape, slice=fixed(None), orientation=widgets.Dropdown(options=['z', 'x', 'y'], description='Orientation')): if orientation == 'z': view = '[slice, ...]' if orientation == 'x': view = '[:, slice, :]' if orientation == 'y': view = '[..., slice]' plt.subplots(*gridShape, figsize=(10, 8)) for i, im in enumerate(imageList): plt.subplot(gridShape[0], gridShape[1], i+1) exec(f'plt.imshow(im{view})') plt.tight_layout() plt.show()images = []for _ in range(4): images.append(np.random.random([15, 50, 50]))interact(show, imageList=fixed(images), gridShape=fixed((2, 2)), slice=(0, images[0].shape[0]-1))