code: def _get_event_channel(fig):
      """Get the event channel associated with a figure.
  
      If the event channel doesn't exist yet, it gets created and added to the
      global ``_event_channels`` dict.
  
      Parameters
      ----------
      fig : matplotlib.figure.Figure | Figure3D
          The figure to get the event channel for.
  
      Returns
      -------
      channel : dict[event -> list]
          The event channel. An event channel is a list mapping string event
          names to a list of callback representing all subscribers to the
          channel.
      """
      import matplotlib
  
      from ._brain import Brain
      from .evoked_field import EvokedField
  
      # Create the event channel if it doesn't exist yet
      if fig not in _event_channels:
          # The channel itself is a dict mapping string event names to a list of
          # subscribers. No subscribers yet for this new event channel.
          _event_channels[fig] = dict()
  
          weakfig = weakref.ref(fig)
  
          # When the figure is closed, its associated event channel should be
          # deleted. This is a good time to set this up.
          def delete_event_channel(event=None, *, weakfig=weakfig):
              """Delete the event channel (callback function)."""
              fig = weakfig()
              if fig is None:
                  return
              publish(
                  fig, event=FigureClosing()
              )  # Notify subscribers of imminent close
              logger.debug(f"unlink(({fig})")
              unlink(
                  fig
              )  # Remove channel from the _event_channel_links dict
              if fig in _event_channels:
                  logger.debug(f"  del _event_channels[{fig}]")
                  del _event_channels[fig]
              if fig in _disabled_event_channels:
                  logger.debug(
                      f"  _disabled_event_channels.remove({fig})"
                  )
                  _disabled_event_channels.remove(fig)
  
          # Hook up the above callback function to the close event of the figure
          # window. How this is done exactly depends on the various figure types
          # MNE-Python has.
          _validate_type(
              fig, (matplotlib.figure.Figure, Brain, EvokedField), "fig"
          )
          if isinstance(fig, matplotlib.figure.Figure):
              fig.canvas.mpl_connect(
                  "close_event", delete_event_channel
              )
          else:
              assert hasattr(
                  fig, "_renderer"
              )  # figures like Brain, EvokedField, etc.
              fig._renderer._window_close_connect(
                  delete_event_channel, after=False
              )
  
      # Now the event channel exists for sure.
      return _event_channels[fig]
  
imports: import contextlib
  import re
  import weakref
  from dataclasses import dataclass
  from typing import Optional, Union
  from matplotlib.colors import Colormap
  from ..utils import _validate_type, fill_doc, logger, verbose, warn
label_desc: Use image node_id 1 for calling a global function with example usage: _get_event_channel(fig) and returns: _event_channels