Skip to content

Commit b72b775

Browse files
ENH Brain.add_label(): also use label.color attribute
1 parent e03c9f8 commit b72b775

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

surfer/viz.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -991,18 +991,19 @@ def add_annotation(self, annot, borders=True, alpha=1, hemi=None,
991991
self.annot_list = al
992992
self._toggle_render(True, views)
993993

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,
995995
borders=False, hemi=None, subdir=None):
996996
"""Add an ROI label to the image.
997997
998998
Parameters
999999
----------
10001000
label : str | instance of Label
10011001
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".
1002+
an object with attributes "hemi", "vertices", "name", and
1003+
optionally "color" and "values" (if scalar_thresh is not None).
10041004
color : matplotlib-style color
1005-
anything matplotlib accepts: string, RGB, hex, etc.
1005+
anything matplotlib accepts: string, RGB, hex, etc. (default
1006+
"crimson")
10061007
alpha : float in [0, 1]
10071008
alpha level to control opacity
10081009
scalar_thresh : None or number
@@ -1028,6 +1029,9 @@ def add_label(self, label, color="crimson", alpha=1, scalar_thresh=None,
10281029
"""
10291030
if isinstance(label, basestring):
10301031
hemi = self._check_hemi(hemi)
1032+
if color is None:
1033+
color = "crimson"
1034+
10311035
if os.path.isfile(label):
10321036
filepath = label
10331037
label_name = os.path.basename(filepath).split('.')[1]
@@ -1058,6 +1062,13 @@ def add_label(self, label, color="crimson", alpha=1, scalar_thresh=None,
10581062
label_name = 'unnamed'
10591063
else:
10601064
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+
10611072
if scalar_thresh is not None:
10621073
scalars = label.values
10631074
except Exception:

0 commit comments

Comments
 (0)