code: def _handle_event_colors(color_dict, unique_events, event_id):
      """Create event-integer-to-color mapping, assigning defaults as needed."""
      default_colors = dict(
          zip(sorted(unique_events), cycle(_get_color_list()))
      )
      # warn if not enough colors
      if color_dict is None:
          if len(unique_events) > len(_get_color_list()):
              warn(
                  "More events than default colors available. You should pass "
                  "a list of unique colors."
              )
      else:
          custom_colors = dict()
          for key, color in color_dict.items():
              if key in unique_events:  # key was a valid event integer
                  custom_colors[key] = color
              elif key in event_id:  # key was an event label
                  custom_colors[event_id[key]] = color
              else:  # key not a valid event, warn and ignore
                  warn(
                      "Event ID %s is in the color dict but is not "
                      "present in events or event_id." % str(key)
                  )
          # warn if color_dict is missing any entries
          unassigned = sorted(set(unique_events) - set(custom_colors))
          if len(unassigned):
              unassigned_str = ", ".join(str(e) for e in unassigned)
              warn(
                  "Color was not assigned for event%s %s. Default colors will "
                  "be used." % (_pl(unassigned), unassigned_str)
              )
          default_colors.update(custom_colors)
      return default_colors
  
imports: import copy
  import io
  import os
  import os.path
  import warnings
  from collections import defaultdict
  from glob import glob
  from itertools import cycle
  from pathlib import Path
  import numpy
  from scipy.signal import filtfilt, freqz, group_delay, lfilter, sosfilt, sosfiltfilt
  from .._fiff.constants import FIFF
  from .._fiff.pick import _DATA_CH_TYPES_SPLIT, _picks_by_type, pick_channels, pick_info, pick_types
  from .._fiff.proj import make_projector
  from .._freesurfer import _check_mri, _mri_orientation, _read_mri_info, _reorient_image
  from ..defaults import DEFAULTS
  from ..filter import estimate_ringing_samples
  from ..fixes import _safe_svd
  from ..rank import compute_rank
  from ..surface import read_surface
  from ..transforms import _frame_to_str, apply_trans
  from ..utils import _check_option, _mask_to_onsets_offsets, _on_missing, _pl, fill_doc, get_subjects_dir, logger, verbose, warn
  from .utils import _figure_agg, _get_color_list, _prepare_trellis, _validate_type, plt_show
label_desc: Use image node_id 16 for calling a global function with example usage: _handle_event_colors(color_dict, unique_events, event_id) and returns: default_colors