Skip to content

ENH: Time-label consistency over time #131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/save_movie.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
data = stc['data']
times = np.arange(data.shape[1]) * stc['tstep'] + stc['tmin']
brain.add_data(data, colormap='hot', vertices=stc['vertices'],
smoothing_steps=10, time=times, time_label='%0.3f s',
hemi=hemi)
smoothing_steps=10, time=times, hemi=hemi,
time_label=lambda t: '%s ms' % int(round(t * 1e3)))

"""
scale colormap
Expand Down
17 changes: 13 additions & 4 deletions surfer/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ def add_data(self, array, min=None, max=None, thresh=None,
colormap="RdBu_r", alpha=1,
vertices=None, smoothing_steps=20, time=None,
time_label="time index=%d", colorbar=True,
hemi=None, remove_existing=False):
hemi=None, remove_existing=False, time_label_size=14):
"""Display data from a numpy array on the surface.

This provides a similar interface to add_overlay, but it displays
Expand Down Expand Up @@ -820,6 +820,8 @@ def add_data(self, array, min=None, max=None, thresh=None,
remove_existing : bool
Remove surface added by previous "add_data" call. Useful for
conserving memory when displaying different data in a loop.
time_label_size : int
Font size of the time label (default 14)
"""
hemi = self._check_hemi(hemi)

Expand Down Expand Up @@ -895,8 +897,10 @@ 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]),
name="time_label", row=row, col=col)
self.add_text(0.95, y_txt, time_label(time[0]),
name="time_label", row=row, col=col,
font_size=time_label_size,
justification='right')
self._toggle_render(True, views)
data['surfaces'] = surfs
data['colorbars'] = bars
Expand Down Expand Up @@ -1385,7 +1389,7 @@ def add_contour_overlay(self, source, min=None, max=None,
self._toggle_render(True, views)

def add_text(self, x, y, text, name, color=None, opacity=1.0,
row=-1, col=-1):
row=-1, col=-1, font_size=None, justification=None):
""" Add a text to the visualization

Parameters
Expand All @@ -1412,6 +1416,11 @@ def add_text(self, x, y, text, name, color=None, opacity=1.0,
text = self.brain_matrix[row, col].add_text(x, y, text,
name, color, opacity)
self.texts_dict[name] = dict(row=row, col=col, text=text)
if font_size is not None:
text.property.font_size = font_size
text.actor.text_scale_mode = 'viewport'
if justification is not None:
text.property.justification = justification

def update_text(self, text, name, row=-1, col=-1):
"""Update text label
Expand Down