From 12f57691635b6eb0f78d85178fc71d4994ceb854 Mon Sep 17 00:00:00 2001 From: Paul McCarthy <pauld.mccarthy@gmail.com> Date: Tue, 8 Jul 2014 16:04:50 +0100 Subject: [PATCH] TimeSeriesPanel changes imagelist volume on mouse clicks/drags --- fsl/fslview/views/timeseriespanel.py | 61 ++++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 7 deletions(-) diff --git a/fsl/fslview/views/timeseriespanel.py b/fsl/fslview/views/timeseriespanel.py index bc1e43a15..2352f7422 100644 --- a/fsl/fslview/views/timeseriespanel.py +++ b/fsl/fslview/views/timeseriespanel.py @@ -12,6 +12,7 @@ import wx import props +import numpy as np import matplotlib as mpl mpl.use('WXAgg') @@ -31,9 +32,19 @@ class TimeSeriesPanel(wx.Panel, props.HasProperties): self._name = '{}_{}'.format(self.__class__.__name__, id(self)) self._figure = plt.Figure() - self._axis = self._figure.add_subplot(1, 1, 1) + self._axis = self._figure.add_subplot(111) self._canvas = Canvas(self, -1, self._figure) + self._figure.subplots_adjust( + top=1.0, bottom=0.0, left=0.0, right=1.0) + + self._figure.patch.set_visible(False) + + self._mouseDown = False + self._canvas.mpl_connect('button_press_event', self._onPlotMouseDown) + self._canvas.mpl_connect('button_release_event', self._onPlotMouseUp) + self._canvas.mpl_connect('motion_notify_event', self._onPlotMouseMove) + self._sizer = wx.BoxSizer(wx.VERTICAL) self.SetSizer(self._sizer) self._sizer.Add(self._canvas, flag=wx.EXPAND, proportion=1) @@ -105,10 +116,11 @@ class TimeSeriesPanel(wx.Panel, props.HasProperties): if vox >= shape or vox < 0: inBounds = False - if inBounds: - data = image.data[x, y, z, :] - self._axis.plot(data, 'r-', lw=2) - else: + if t < image.shape[3]: + self._axis.axvline(t, lw=2, c='#000080', alpha=0.6) + + if not inBounds: + self._axis.text( 0.5, 0.5, @@ -117,7 +129,42 @@ class TimeSeriesPanel(wx.Panel, props.HasProperties): ha='center', transform=self._axis.transAxes) - if t < image.shape[3]: - self._axis.axvline(t, lw=2, c='#000080') + data = image.data[x, y, z, :] + self._axis.plot(data, 'r-', lw=2) + + xmin = 0 + xmax = image.shape[3] + ymin = data.min() + ymax = data.max() + + xlen = xmax - xmin + ylen = ymax - ymin + + self._axis.grid(True) + self._axis.set_xlim((xmin - xlen * 0.05, xmax + xlen * 0.05)) + self._axis.set_ylim((ymin - ylen * 0.05, ymax + ylen * 0.05)) + + yticks = np.linspace(ymin, ymax, 5) + + self._axis.set_yticks(yticks) + + for tick in self._axis.yaxis.get_major_ticks(): + tick.set_pad(-15) + tick.label1.set_horizontalalignment('left') + for tick in self._axis.xaxis.get_major_ticks(): + tick.set_pad(-20) self._canvas.draw() + self.Refresh() + + def _onPlotMouseDown(self, ev): + self._mouseDown = True + + def _onPlotMouseUp(self, ev): + self._mouseDown = False + + def _onPlotMouseMove(self, ev): + if not self._mouseDown: return + if ev.inaxes != self._axis: return + + self._imageList.volume = np.floor(ev.xdata) -- GitLab