Commit 8d3307f3 authored by Matthijs's avatar Matthijs
Browse files

docstrings, parameter in XYZStackViewer

parent eae38efd
......@@ -5,13 +5,19 @@ from matplotlib.widgets import Slider
class SingleStackViewer:
def __init__(self, volume):
"""
Create window showing a slice of the 3d data, allows to scan the slice position using j, k keys.
Note that k will also change the x-axis if the mouse is hovering over the window.
:param volume: real-valued np.ndarray (3D)
"""
fig, ax = plt.subplots()
ax.volume = volume
ax.index = volume.shape[0] // 2
maxval = max(abs(volume))
im = ax.imshow(volume[ax.index], cmap='seismic', vmin=-maxval, vmax=maxval)
plt.colorbar(im)
ax.set_title('use [j,k] to navigate')
ax.set_title('Use [j,k] to navigate')
fig.canvas.mpl_connect('key_press_event', self.process_key)
def process_key(self, event):
......@@ -38,17 +44,20 @@ class SingleStackViewer:
class XYZStackViewer:
def __init__(self, volume, limit_sliders=(0, 0, 0), cmap='seismic'):
def __init__(self, volume, limit_sliders=(0, 0, 0), cmap: str = 'seismic', clim: tuple = (None, None)):
"""
Dynamic matplotlib plot showing slices out of a 3d dataset
:param volume: real-valued 3d numpy array
:param limit_sliders: sliders allow range given by [limit, N-limit], where N is the maximal length
:param cmap: color map to use (e.g. 'seismic' or 'viridis'). For 'seismic, will center on 0, else'
:param clim: tuple with the min-max values of the colorscale
"""
self.volume = volume
if cmap == 'seismic':
if clim[0] is not None:
self.minval, self.maxval = clim
elif cmap == 'seismic':
self.maxval = max(abs(volume))
self.minval = -self.maxval
else:
......@@ -57,7 +66,7 @@ class XYZStackViewer:
self.indices = [s // 2 for s in volume.shape]
self.shape = self.volume.shape
self.fig, self.ax = plt.subplots(1, 3, figsize=(10,4))
self.fig, self.ax = plt.subplots(1, 3, figsize=(10, 4))
im = self.ax[0].imshow(volume[self.indices[0], :, :], cmap=cmap, vmin=-self.minval, vmax=self.maxval)
im = self.ax[1].imshow(volume[:, self.indices[0], :], cmap=cmap, vmin=-self.minval, vmax=self.maxval)
......@@ -72,17 +81,17 @@ class XYZStackViewer:
axcolor = None # 'lightgoldenrodyellow'
sliderlength = 0.17
subax1 = self.fig.add_axes([0.15, 0.1, sliderlength, 0.03], facecolor=axcolor)
self.ax1slider = Slider(subax1, 'Slice', 0+limit_sliders[0], self.shape[0]-limit_sliders[0],
self.ax1slider = Slider(subax1, 'Slice', 0 + limit_sliders[0], self.shape[0] - limit_sliders[0],
valinit=self.indices[0], valstep=1, valfmt='%d')
self.ax1slider.on_changed(self.update_1)
subax2 = self.fig.add_axes([0.41, 0.1, sliderlength, 0.03], facecolor=axcolor)
self.ax2slider = Slider(subax2, 'Slice', 0+limit_sliders[1], self.shape[0]-limit_sliders[1],
self.ax2slider = Slider(subax2, 'Slice', 0 + limit_sliders[1], self.shape[0] - limit_sliders[1],
valinit=self.indices[0], valstep=1, valfmt='%d')
self.ax2slider.on_changed(self.update_2)
subax3 = self.fig.add_axes([0.67, 0.1, sliderlength, 0.03], facecolor=axcolor)
self.ax3slider = Slider(subax3, 'Slice', 0+limit_sliders[2], self.shape[0]-limit_sliders[2],
self.ax3slider = Slider(subax3, 'Slice', 0 + limit_sliders[2], self.shape[0] - limit_sliders[2],
valinit=self.indices[0], valstep=1, valfmt='%d')
self.ax3slider.on_changed(self.update_3)
......@@ -107,20 +116,3 @@ class XYZStackViewer:
self.ax[2].images[0].set_array(self.volume[:, :, int(n)])
self.fig.canvas.draw_idle()
# def process_key(self, event):
# """Look for special events captured by mpl_connect, send to correct function """
# fig = event.canvas.figure
# ax = fig.axes[0]
# if event.key == 'j':
# self.previous_slice(ax)
# elif event.key == 'k':
# self.next_slice(ax)
# fig.canvas.draw()
#
# def previous_slice(self, ax):
# """Go to the previous slice on all plots."""
# # do stuff: set_array for all, set self.indices, set_val for sliders
#
# def next_slice(self, ax):
# """Go to the next slice."""
# # do something
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment