Commit c172fd84 authored by Matthijs's avatar Matthijs
Browse files

improved handling of RGB plots

parent 27ef7933
......@@ -66,6 +66,12 @@ class XYZStackViewer:
if get_backend() not in good_backends:
warn(Warning('Current matplotlib backend may not allow for optimal funcionality! Use, e.g., Qt'))
if volume.ndim == 4 and volume.shape[-1] in [3,4]:
rgb_plot = True
else:
# assert volume.ndim == 3, 'Functionality is designed for 3D arrays'
rgb_plot = False
if cmap is not None:
show_colorbar = True
else:
......@@ -76,6 +82,7 @@ class XYZStackViewer:
elif iscomplexobj(volume):
self.cast_fn = complex_to_rgb
show_colorbar = False
rgb_plot = True
else:
def dummy(array):
return array
......@@ -91,8 +98,9 @@ class XYZStackViewer:
self.maxval = max(abs(volume))
self.minval = -1*self.maxval
else:
self.maxval = max(volume)
self.minval = min([0, min(volume)])
if not rgb_plot:
self.maxval = max(self.cast_fn(volume))
self.minval = min([0, min(self.cast_fn(volume))])
self.fig, self.ax = plt.subplots(1, 3, figsize=(10, 4))
im = self.ax[0].imshow(self.cast_fn(volume[self.indices[0], :, :]), cmap=cmap, vmin=self.minval,
......@@ -105,7 +113,7 @@ class XYZStackViewer:
self.ax[2].set_yticks([])
self.fig.subplots_adjust(bottom=0.1, right=0.85)
if show_colorbar:
if show_colorbar and not rgb_plot:
cbar_ax = self.fig.add_axes([0.87, 0.2, 0.01, 0.6])
plt.colorbar(im, cax=cbar_ax)
......@@ -128,7 +136,6 @@ class XYZStackViewer:
self.fig.show()
def update_1(self, n):
"""Update subfigure 1 on change of the slider """
self.indices[0] = int(n)
......
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