Commit 7ad2bb43 authored by Matthijs's avatar Matthijs
Browse files

MPL backend check

parent 8d3307f3
import matplotlib.pyplot as plt
from matplotlib import get_backend
from numpy import max, min
from matplotlib.widgets import Slider
from warnings import warn
good_backends = ['Qt5Agg','TkAgg','Qt4Agg']
class SingleStackViewer:
def __init__(self, volume):
......@@ -11,6 +14,8 @@ class SingleStackViewer:
:param volume: real-valued np.ndarray (3D)
"""
if get_backend() not in good_backends:
warn(Warning('Current matplotlib backend may not allow for optimal funcionality! Use, e.g., Qt'))
fig, ax = plt.subplots()
ax.volume = volume
ax.index = volume.shape[0] // 2
......@@ -53,8 +58,12 @@ class XYZStackViewer:
: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 get_backend() not in good_backends:
warn(Warning('Current matplotlib backend may not allow for optimal funcionality! Use, e.g., Qt'))
self.volume = volume
self.indices = [s // 2 for s in volume.shape]
self.shape = self.volume.shape
if clim[0] is not None:
self.minval, self.maxval = clim
elif cmap == 'seismic':
......@@ -63,14 +72,11 @@ class XYZStackViewer:
else:
self.maxval = max(volume)
self.minval = min([0, min(volume)])
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))
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)
im = self.ax[2].imshow(volume[:, :, self.indices[0]], cmap=cmap, vmin=-self.minval, vmax=self.maxval)
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)
im = self.ax[2].imshow(volume[:, :, self.indices[0]], cmap=cmap, vmin=self.minval, vmax=self.maxval)
self.ax[1].set_yticks([])
self.ax[2].set_yticks([])
......@@ -116,3 +122,20 @@ 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