@@ -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