@@ -768,7 +768,7 @@ def add_data(self, array, min=None, max=None, thresh=None,
768
768
colormap = "RdBu_r" , alpha = 1 ,
769
769
vertices = None , smoothing_steps = 20 , time = None ,
770
770
time_label = "time index=%d" , colorbar = True ,
771
- hemi = None ):
771
+ hemi = None , remove_existing = False ):
772
772
"""Display data from a numpy array on the surface.
773
773
774
774
This provides a similar interface to add_overlay, but it displays
@@ -817,6 +817,9 @@ def add_data(self, array, min=None, max=None, thresh=None,
817
817
If None, it is assumed to belong to the hemipshere being
818
818
shown. If two hemispheres are being shown, an error will
819
819
be thrown.
820
+ remove_existing : bool
821
+ Remove surface added by previous "add_data" call. Useful for
822
+ conserving memory when displaying different data in a loop.
820
823
"""
821
824
hemi = self ._check_hemi (hemi )
822
825
@@ -895,6 +898,11 @@ def add_data(self, array, min=None, max=None, thresh=None,
895
898
data ['surfaces' ] = surfs
896
899
data ['colorbars' ] = bars
897
900
data ['orig_ctable' ] = ct
901
+
902
+ if remove_existing and self .data_dict [hemi ] is not None :
903
+ for surf in self .data_dict [hemi ]['surfaces' ]:
904
+ surf .parent .parent .remove ()
905
+
898
906
self .data_dict [hemi ] = data
899
907
900
908
def add_annotation (self , annot , borders = True , alpha = 1 , hemi = None ,
0 commit comments