Skip to content

Commit 170a637

Browse files
ENH Brain: allow time_label to be function
1 parent a7b4097 commit 170a637

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

surfer/viz.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -808,8 +808,9 @@ def add_data(self, array, min=None, max=None, thresh=None,
808808
Default : 20
809809
time : numpy array
810810
time points in the data array (if data is 2D)
811-
time_label : str | None
812-
format of the time label (or None for no label)
811+
time_label : str | callable | None
812+
format of the time label (a format string, a function that maps
813+
floating point time values to strings, or None for no label)
813814
colorbar : bool
814815
whether to add a colorbar to the figure
815816
hemi : str | None
@@ -869,6 +870,8 @@ def add_data(self, array, min=None, max=None, thresh=None,
869870
if not self.n_times == len(time):
870871
raise ValueError('time is not the same length as '
871872
'array.shape[1]')
873+
if isinstance(time_label, basestring):
874+
time_label = lambda x: time_label % x
872875
data["time_label"] = time_label
873876
data["time"] = time
874877
data["time_idx"] = 0
@@ -891,7 +894,7 @@ def add_data(self, array, min=None, max=None, thresh=None,
891894
bars.append(bar)
892895
row, col = np.unravel_index(bi, self.brain_matrix.shape)
893896
if array.ndim == 2 and time_label is not None:
894-
self.add_text(0.05, y_txt, time_label % time[0],
897+
self.add_text(0.05, y_txt, time_label(time[0]),
895898
name="time_label", row=row, col=col)
896899
self._toggle_render(True, views)
897900
data['surfaces'] = surfs
@@ -1609,7 +1612,7 @@ def set_data_time_index(self, time_idx, interpolation='quadratic'):
16091612
time = ifunc(time_idx)
16101613
else:
16111614
time = data["time"][time_idx]
1612-
self.update_text(data["time_label"] % time, "time_label")
1615+
self.update_text(data["time_label"](time), "time_label")
16131616
self._toggle_render(True, views)
16141617

16151618
@property

0 commit comments

Comments
 (0)