Skip to content

Commit bcdd7a0

Browse files
committed
Merge pull request #131 from christianbrodbeck/timelabel
ENH: Time-label consistency over time
2 parents c50af8c + 188c833 commit bcdd7a0

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

examples/save_movie.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
data = stc['data']
2828
times = np.arange(data.shape[1]) * stc['tstep'] + stc['tmin']
2929
brain.add_data(data, colormap='hot', vertices=stc['vertices'],
30-
smoothing_steps=10, time=times, time_label='%0.3f s',
31-
hemi=hemi)
30+
smoothing_steps=10, time=times, hemi=hemi,
31+
time_label=lambda t: '%s ms' % int(round(t * 1e3)))
3232

3333
"""
3434
scale colormap

surfer/viz.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ def add_data(self, array, min=None, max=None, thresh=None,
767767
colormap="RdBu_r", alpha=1,
768768
vertices=None, smoothing_steps=20, time=None,
769769
time_label="time index=%d", colorbar=True,
770-
hemi=None, remove_existing=False):
770+
hemi=None, remove_existing=False, time_label_size=14):
771771
"""Display data from a numpy array on the surface.
772772
773773
This provides a similar interface to add_overlay, but it displays
@@ -820,6 +820,8 @@ def add_data(self, array, min=None, max=None, thresh=None,
820820
remove_existing : bool
821821
Remove surface added by previous "add_data" call. Useful for
822822
conserving memory when displaying different data in a loop.
823+
time_label_size : int
824+
Font size of the time label (default 14)
823825
"""
824826
hemi = self._check_hemi(hemi)
825827

@@ -895,8 +897,10 @@ def add_data(self, array, min=None, max=None, thresh=None,
895897
bars.append(bar)
896898
row, col = np.unravel_index(bi, self.brain_matrix.shape)
897899
if array.ndim == 2 and time_label is not None:
898-
self.add_text(0.05, y_txt, time_label(time[0]),
899-
name="time_label", row=row, col=col)
900+
self.add_text(0.95, y_txt, time_label(time[0]),
901+
name="time_label", row=row, col=col,
902+
font_size=time_label_size,
903+
justification='right')
900904
self._toggle_render(True, views)
901905
data['surfaces'] = surfs
902906
data['colorbars'] = bars
@@ -1385,7 +1389,7 @@ def add_contour_overlay(self, source, min=None, max=None,
13851389
self._toggle_render(True, views)
13861390

13871391
def add_text(self, x, y, text, name, color=None, opacity=1.0,
1388-
row=-1, col=-1):
1392+
row=-1, col=-1, font_size=None, justification=None):
13891393
""" Add a text to the visualization
13901394
13911395
Parameters
@@ -1412,6 +1416,11 @@ def add_text(self, x, y, text, name, color=None, opacity=1.0,
14121416
text = self.brain_matrix[row, col].add_text(x, y, text,
14131417
name, color, opacity)
14141418
self.texts_dict[name] = dict(row=row, col=col, text=text)
1419+
if font_size is not None:
1420+
text.property.font_size = font_size
1421+
text.actor.text_scale_mode = 'viewport'
1422+
if justification is not None:
1423+
text.property.justification = justification
14151424

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

0 commit comments

Comments
 (0)