@@ -991,18 +991,19 @@ def add_annotation(self, annot, borders=True, alpha=1, hemi=None,
991
991
self .annot_list = al
992
992
self ._toggle_render (True , views )
993
993
994
- def add_label (self , label , color = "crimson" , alpha = 1 , scalar_thresh = None ,
994
+ def add_label (self , label , color = None , alpha = 1 , scalar_thresh = None ,
995
995
borders = False , hemi = None , subdir = None ):
996
996
"""Add an ROI label to the image.
997
997
998
998
Parameters
999
999
----------
1000
1000
label : str | instance of Label
1001
1001
label filepath or name. Can also be an instance of
1002
- an object with attributes "hemi", "vertices", "name",
1003
- and (if scalar_thresh is not None) "values".
1004
- color : matplotlib-style color
1005
- anything matplotlib accepts: string, RGB, hex, etc.
1002
+ an object with attributes "hemi", "vertices", "name", and
1003
+ optionally "color" and "values" (if scalar_thresh is not None).
1004
+ color : matplotlib-style color | None
1005
+ anything matplotlib accepts: string, RGB, hex, etc. (default
1006
+ "crimson")
1006
1007
alpha : float in [0, 1]
1007
1008
alpha level to control opacity
1008
1009
scalar_thresh : None or number
@@ -1026,8 +1027,11 @@ def add_label(self, label, color="crimson", alpha=1, scalar_thresh=None,
1026
1027
-----
1027
1028
To remove previously added labels, run Brain.remove_labels().
1028
1029
"""
1029
- hemi = self ._check_hemi (hemi )
1030
1030
if isinstance (label , basestring ):
1031
+ hemi = self ._check_hemi (hemi )
1032
+ if color is None :
1033
+ color = "crimson"
1034
+
1031
1035
if os .path .isfile (label ):
1032
1036
filepath = label
1033
1037
label_name = os .path .basename (filepath ).split ('.' )[1 ]
@@ -1052,12 +1056,19 @@ def add_label(self, label, color="crimson", alpha=1, scalar_thresh=None,
1052
1056
else :
1053
1057
# try to extract parameters from label instance
1054
1058
try :
1055
- lhemi = label .hemi
1059
+ hemi = label .hemi
1056
1060
ids = label .vertices
1057
1061
if label .name is None :
1058
1062
label_name = 'unnamed'
1059
1063
else :
1060
1064
label_name = str (label .name )
1065
+
1066
+ if color is None :
1067
+ if hasattr (label , 'color' ) and label .color is not None :
1068
+ color = label .color
1069
+ else :
1070
+ color = "crimson"
1071
+
1061
1072
if scalar_thresh is not None :
1062
1073
scalars = label .values
1063
1074
except Exception :
@@ -1066,9 +1077,8 @@ def add_label(self, label, color="crimson", alpha=1, scalar_thresh=None,
1066
1077
'must have attributes "hemi", "vertices", '
1067
1078
'"name", and (if scalar_thresh is not None)'
1068
1079
'"values"' )
1069
- if not lhemi == hemi :
1070
- raise ValueError ('label hemisphere (%s) and brain hemisphere '
1071
- '(%s) must match' % (lhemi , hemi ))
1080
+ hemi = self ._check_hemi (hemi )
1081
+
1072
1082
if scalar_thresh is not None :
1073
1083
ids = ids [scalars >= scalar_thresh ]
1074
1084
0 commit comments