Skip to content

Commit

Permalink
Merge pull request #129 from christianbrodbeck/timelabel
Browse files Browse the repository at this point in the history
ENH Brain:  allow time_label to be function
  • Loading branch information
larsoner committed May 5, 2015
2 parents a7b4097 + cad4820 commit b8b8c10
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
12 changes: 6 additions & 6 deletions examples/plot_meg_inverse_solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,20 @@
vertices = stc['vertices']

"""
time points in milliseconds
time points (in seconds)
"""
time = 1e3 * np.linspace(stc['tmin'],
stc['tmin'] + data.shape[1] * stc['tstep'],
data.shape[1])
time = np.linspace(stc['tmin'], stc['tmin'] + data.shape[1] * stc['tstep'],
data.shape[1])

"""
colormap to use
"""
colormap = 'hot'

"""
label for time annotation
label for time annotation in milliseconds
"""
time_label = 'time=%0.2f ms'
time_label = lambda t: 'time=%0.2f ms' % (t * 1e3)

brain.add_data(data, colormap=colormap, vertices=vertices,
smoothing_steps=10, time=time, time_label=time_label,
Expand Down
12 changes: 8 additions & 4 deletions surfer/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,8 +808,9 @@ def add_data(self, array, min=None, max=None, thresh=None,
Default : 20
time : numpy array
time points in the data array (if data is 2D)
time_label : str | None
format of the time label (or None for no label)
time_label : str | callable | None
format of the time label (a format string, a function that maps
floating point time values to strings, or None for no label)
colorbar : bool
whether to add a colorbar to the figure
hemi : str | None
Expand Down Expand Up @@ -869,6 +870,9 @@ def add_data(self, array, min=None, max=None, thresh=None,
if not self.n_times == len(time):
raise ValueError('time is not the same length as '
'array.shape[1]')
if isinstance(time_label, basestring):
time_label_fmt = time_label
time_label = lambda x: time_label_fmt % x
data["time_label"] = time_label
data["time"] = time
data["time_idx"] = 0
Expand All @@ -891,7 +895,7 @@ def add_data(self, array, min=None, max=None, thresh=None,
bars.append(bar)
row, col = np.unravel_index(bi, self.brain_matrix.shape)
if array.ndim == 2 and time_label is not None:
self.add_text(0.05, y_txt, time_label % time[0],
self.add_text(0.05, y_txt, time_label(time[0]),
name="time_label", row=row, col=col)
self._toggle_render(True, views)
data['surfaces'] = surfs
Expand Down Expand Up @@ -1609,7 +1613,7 @@ def set_data_time_index(self, time_idx, interpolation='quadratic'):
time = ifunc(time_idx)
else:
time = data["time"][time_idx]
self.update_text(data["time_label"] % time, "time_label")
self.update_text(data["time_label"](time), "time_label")
self._toggle_render(True, views)

@property
Expand Down

0 comments on commit b8b8c10

Please sign in to comment.