Skip to content

Commit ba7b0a0

Browse files
committed
ENH: Enable percentile value limits
1 parent c371f8b commit ba7b0a0

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

nibabel/viewers.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ def __init__(self, data, affine=None, axes=None, title=None, vlim=None):
6363
title.
6464
vlim : array-like or None, optional
6565
Value limits to display image and time series. Can be None
66-
(default) to derive limits from data.
66+
(default) to derive limits from data. Bounds can be of the
67+
form ``'x%'`` to use the ``x`` percentile of the data.
6768
"""
6869
# Use these late imports of matplotlib so that we have some hope that
6970
# the test functions are the first to set the matplotlib backend. The
@@ -81,6 +82,13 @@ def __init__(self, data, affine=None, axes=None, title=None, vlim=None):
8182
affine = np.array(affine, float) if affine is not None else np.eye(4)
8283
if affine.shape != (4, 4):
8384
raise ValueError('affine must be a 4x4 matrix')
85+
86+
if vlim is not None:
87+
percentiles = all(isinstance(lim, str) and lim[-1] == '%'
88+
for lim in vlim)
89+
if percentiles:
90+
vlim = np.percentile(data, [float(lim[:-1]) for lim in vlim])
91+
8492
# determine our orientation
8593
self._affine = affine
8694
codes = axcodes2ornt(aff2axcodes(self._affine))

0 commit comments

Comments
 (0)