From 4f9aeec2f28920431f281ad027b298f91c18c6de Mon Sep 17 00:00:00 2001 From: Ross Markello Date: Thu, 9 Apr 2020 09:58:30 -0400 Subject: [PATCH] RF: Better under/overlay handling --- nibabel/viewers.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/nibabel/viewers.py b/nibabel/viewers.py index aed720287d..ef48a62ac3 100644 --- a/nibabel/viewers.py +++ b/nibabel/viewers.py @@ -381,6 +381,7 @@ def set_overlay(self, data, affine=None, threshold=None, cmap='viridis', (target_shape, self._affine)).dataobj affine = self._affine + # we already have a plotted overlay if self._overlay is not None: # remove all images + cross hair lines for nn, im in enumerate(self._overlay._ims): @@ -393,12 +394,13 @@ def set_overlay(self, data, affine=None, threshold=None, cmap='viridis', a = self._axes.pop(-1) a.remove() - # create an axis if we have a 4D overlay (vs a 3D underlay) axes = self._axes o_n_volumes = int(np.prod(data.shape[3:])) - if o_n_volumes > self.n_volumes: + # 3D underlay, 4D overlay + if o_n_volumes > self.n_volumes and self.n_volumes == 1: axes += [axes[0].figure.add_subplot(224)] - elif o_n_volumes < self.n_volumes: + # 4D underlay, 3D overlay + elif o_n_volumes < self.n_volumes and o_n_volumes == 1: axes = axes[:-1] # mask array for provided threshold