Skip to content

Commit b8b8c10

Browse files
committed
Merge pull request #129 from christianbrodbeck/timelabel
ENH Brain: allow time_label to be function
2 parents a7b4097 + cad4820 commit b8b8c10

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

examples/plot_meg_inverse_solution.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,20 @@
3939
vertices = stc['vertices']
4040

4141
"""
42-
time points in milliseconds
42+
time points (in seconds)
4343
"""
44-
time = 1e3 * np.linspace(stc['tmin'],
45-
stc['tmin'] + data.shape[1] * stc['tstep'],
46-
data.shape[1])
44+
time = np.linspace(stc['tmin'], stc['tmin'] + data.shape[1] * stc['tstep'],
45+
data.shape[1])
46+
4747
"""
4848
colormap to use
4949
"""
5050
colormap = 'hot'
5151

5252
"""
53-
label for time annotation
53+
label for time annotation in milliseconds
5454
"""
55-
time_label = 'time=%0.2f ms'
55+
time_label = lambda t: 'time=%0.2f ms' % (t * 1e3)
5656

5757
brain.add_data(data, colormap=colormap, vertices=vertices,
5858
smoothing_steps=10, time=time, time_label=time_label,

surfer/viz.py

Lines changed: 8 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,9 @@ 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_fmt = time_label
875+
time_label = lambda x: time_label_fmt % x
872876
data["time_label"] = time_label
873877
data["time"] = time
874878
data["time_idx"] = 0
@@ -891,7 +895,7 @@ def add_data(self, array, min=None, max=None, thresh=None,
891895
bars.append(bar)
892896
row, col = np.unravel_index(bi, self.brain_matrix.shape)
893897
if array.ndim == 2 and time_label is not None:
894-
self.add_text(0.05, y_txt, time_label % time[0],
898+
self.add_text(0.05, y_txt, time_label(time[0]),
895899
name="time_label", row=row, col=col)
896900
self._toggle_render(True, views)
897901
data['surfaces'] = surfs
@@ -1609,7 +1613,7 @@ def set_data_time_index(self, time_idx, interpolation='quadratic'):
16091613
time = ifunc(time_idx)
16101614
else:
16111615
time = data["time"][time_idx]
1612-
self.update_text(data["time_label"] % time, "time_label")
1616+
self.update_text(data["time_label"](time), "time_label")
16131617
self._toggle_render(True, views)
16141618

16151619
@property

0 commit comments

Comments
 (0)