Skip to content

Commit 3193506

Browse files
committed
ENH: Add manual value limits to OrthoSlicer3D
Pass kwargs to OrthoSlicer3D from SpatialImage.orthoview()
1 parent ec4567f commit 3193506

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

nibabel/spatialimages.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ def __getitem__(self):
663663
"array data with `img.dataobj[slice]` or "
664664
"`img.get_data()[slice]`")
665665

666-
def orthoview(self):
666+
def orthoview(self, **kwargs):
667667
"""Plot the image using OrthoSlicer3D
668668
669669
Returns
@@ -678,4 +678,4 @@ def orthoview(self):
678678
the figure.
679679
"""
680680
return OrthoSlicer3D(self.dataobj, self.affine,
681-
title=self.get_filename())
681+
title=self.get_filename(), **kwargs)

nibabel/viewers.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class OrthoSlicer3D(object):
4242
"""
4343
# Skip doctest above b/c not all systems have mpl installed
4444

45-
def __init__(self, data, affine=None, axes=None, title=None):
45+
def __init__(self, data, affine=None, axes=None, title=None, vlim=None):
4646
"""
4747
Parameters
4848
----------
@@ -61,6 +61,9 @@ def __init__(self, data, affine=None, axes=None, title=None):
6161
title : str or None, optional
6262
The title to display. Can be None (default) to display no
6363
title.
64+
vlim : array-like or None, optional
65+
Value limits to display image and time series. Can be None
66+
(default) to derive limits from data.
6467
"""
6568
# Use these late imports of matplotlib so that we have some hope that
6669
# the test functions are the first to set the matplotlib backend. The
@@ -90,7 +93,7 @@ def __init__(self, data, affine=None, axes=None, title=None):
9093
self._volume_dims = data.shape[3:]
9194
self._current_vol_data = data[:, :, :, 0] if data.ndim > 3 else data
9295
self._data = data
93-
self._clim = np.percentile(data, (1., 99.))
96+
self._clim = np.percentile(data, (1., 99.)) if vlim is None else vlim
9497
del data
9598

9699
if axes is None: # make the axes
@@ -183,8 +186,11 @@ def __init__(self, data, affine=None, axes=None, title=None):
183186
ax.set_xticks(np.unique(np.linspace(0, self.n_volumes - 1,
184187
5).astype(int)))
185188
ax.set_xlim(x[0], x[-1])
186-
yl = [self._data.min(), self._data.max()]
187-
yl = [l + s * np.diff(lims)[0] for l, s in zip(yl, [-1.01, 1.01])]
189+
if vlim is None:
190+
yl = [self._data.min(), self._data.max()]
191+
yl = [l + s * np.diff(lims)[0] for l, s in zip(yl, [-1.01, 1.01])]
192+
else:
193+
yl = vlim
188194
patch = mpl_patch.Rectangle([-0.5, yl[0]], 1., np.diff(yl)[0],
189195
fill=True, facecolor=(0, 1, 0),
190196
edgecolor=(0, 1, 0), alpha=0.25)

0 commit comments

Comments
 (0)