|
27 | 27 | _handle_decim, |
28 | 28 | _handle_precompute, |
29 | 29 | _make_event_color_dict, |
| 30 | + _normalize_annotation_colors, |
30 | 31 | _shorten_path_from_middle, |
31 | 32 | ) |
32 | 33 |
|
@@ -115,7 +116,7 @@ def plot_raw( |
115 | 116 | annotation_colors : dict | None |
116 | 117 | A dictionary mapping annotation description strings to colors. Use this to |
117 | 118 | override the default color assigned to specific annotation types (e.g., |
118 | | - ``dict(bad_segment='orange')``). Colors can be any valid matplotlib color |
| 119 | + ``dict(bad_segment='orange')``). Colors can be any valid Matplotlib color |
119 | 120 | specification. Keys that do not match any annotation description in the data |
120 | 121 | will trigger a warning. If ``None`` (default), automatic colors are used. |
121 | 122 |
|
@@ -353,24 +354,9 @@ def plot_raw( |
353 | 354 |
|
354 | 355 | # handle annotation_colors |
355 | 356 | if annotation_colors is not None: |
356 | | - from matplotlib.colors import to_hex |
357 | | - |
358 | | - _validate_type(annotation_colors, dict, "annotation_colors") |
359 | | - normalized = {} |
360 | | - for k, v in annotation_colors.items(): |
361 | | - try: |
362 | | - normalized[k] = to_hex(v) |
363 | | - except ValueError: |
364 | | - raise ValueError( |
365 | | - f"annotation_colors[{k!r}] is not a valid matplotlib color: {v!r}" |
366 | | - ) from None |
367 | | - unknown = set(normalized) - set(raw.annotations.description) |
368 | | - if unknown: |
369 | | - warn( |
370 | | - "The following annotation_colors keys do not match any " |
371 | | - f"annotation description in the data: {sorted(unknown)}" |
372 | | - ) |
373 | | - annotation_colors = normalized |
| 357 | + annotation_colors = _normalize_annotation_colors( |
| 358 | + annotation_colors, raw.annotations |
| 359 | + ) |
374 | 360 |
|
375 | 361 | # handle event colors |
376 | 362 | event_color_dict = _make_event_color_dict(event_color, events, event_id) |
|
0 commit comments