@@ -808,8 +808,9 @@ def add_data(self, array, min=None, max=None, thresh=None,
808
808
Default : 20
809
809
time : numpy array
810
810
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)
813
814
colorbar : bool
814
815
whether to add a colorbar to the figure
815
816
hemi : str | None
@@ -869,6 +870,9 @@ def add_data(self, array, min=None, max=None, thresh=None,
869
870
if not self .n_times == len (time ):
870
871
raise ValueError ('time is not the same length as '
871
872
'array.shape[1]' )
873
+ if isinstance (time_label , basestring ):
874
+ time_label_fmt = time_label
875
+ time_label = lambda x : time_label_fmt % x
872
876
data ["time_label" ] = time_label
873
877
data ["time" ] = time
874
878
data ["time_idx" ] = 0
@@ -891,7 +895,7 @@ def add_data(self, array, min=None, max=None, thresh=None,
891
895
bars .append (bar )
892
896
row , col = np .unravel_index (bi , self .brain_matrix .shape )
893
897
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 ]) ,
895
899
name = "time_label" , row = row , col = col )
896
900
self ._toggle_render (True , views )
897
901
data ['surfaces' ] = surfs
@@ -1609,7 +1613,7 @@ def set_data_time_index(self, time_idx, interpolation='quadratic'):
1609
1613
time = ifunc (time_idx )
1610
1614
else :
1611
1615
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" )
1613
1617
self ._toggle_render (True , views )
1614
1618
1615
1619
@property
0 commit comments