code: def test_plot_events():
      """Test plotting events."""
      event_labels = {"aud_l": 1, "aud_r": 2, "vis_l": 3, "vis_r": 4}
      color = {1: "green", 2: "yellow", 3: "red", 4: "c"}
      raw = _get_raw()
      events = _get_events()
      fig = plot_events(events, raw.info["sfreq"], raw.first_samp)
      assert (
          fig.axes[0].get_legend() is not None
      )  # legend even with no event_id
      plot_events(
          events, raw.info["sfreq"], raw.first_samp, equal_spacing=False
      )
      # Test plotting events without sfreq
      plot_events(events, first_samp=raw.first_samp)
      with pytest.warns(RuntimeWarning, match="will be ignored"):
          fig = plot_events(
              events,
              raw.info["sfreq"],
              raw.first_samp,
              event_id=event_labels,
          )
      assert fig.axes[0].get_legend() is not None
      with pytest.warns(RuntimeWarning, match="Color was not assigned"):
          plot_events(
              events, raw.info["sfreq"], raw.first_samp, color=color
          )
      with pytest.warns(
          RuntimeWarning, match=r"vent \d+ missing from event_id"
      ):
          plot_events(
              events,
              raw.info["sfreq"],
              raw.first_samp,
              event_id=event_labels,
              color=color,
          )
      multimatch = (
          r"event \d+ missing from event_id|in the color dict but is"
      )
      with pytest.warns(RuntimeWarning, match=multimatch):
          plot_events(
              events,
              raw.info["sfreq"],
              raw.first_samp,
              event_id={"aud_l": 1},
              color=color,
          )
      extra_id = {"missing": 111}
      with pytest.raises(
          ValueError, match="from event_id is not present in"
      ):
          plot_events(
              events,
              raw.info["sfreq"],
              raw.first_samp,
              event_id=extra_id,
          )
      with pytest.raises(RuntimeError, match="No usable event IDs"):
          plot_events(
              events,
              raw.info["sfreq"],
              raw.first_samp,
              event_id=extra_id,
              on_missing="ignore",
          )
      extra_id = {"aud_l": 1, "missing": 111}
      with pytest.warns(
          RuntimeWarning, match="from event_id is not present in"
      ):
          plot_events(
              events,
              raw.info["sfreq"],
              raw.first_samp,
              event_id=extra_id,
              on_missing="warn",
          )
      with pytest.warns(RuntimeWarning, match="event 2 missing"):
          plot_events(
              events,
              raw.info["sfreq"],
              raw.first_samp,
              event_id=extra_id,
              on_missing="ignore",
          )
      events = events[events[:, 2] == 1]
      assert len(events) > 0
      plot_events(
          events,
          raw.info["sfreq"],
          raw.first_samp,
          event_id=extra_id,
          on_missing="ignore",
      )
      with pytest.raises(ValueError, match="No events"):
          plot_events(np.empty((0, 3)))
  
imports: from pathlib import Path
  import matplotlib.pyplot
  import numpy
  import pytest
  from numpy.testing import assert_array_equal
  from mne import SourceEstimate, pick_events, read_cov, read_dipole, read_events, read_evokeds, read_source_spaces
  from mne.chpi import compute_chpi_snr
  from mne.datasets import testing
  from mne.filter import create_filter
  from mne.io import read_raw_fif
  from mne.minimum_norm import read_inverse_operator
  from mne.time_frequency import CrossSpectralDensity
  from mne.viz import plot_bem, plot_chpi_snr, plot_csd, plot_events, plot_filter, plot_snr_estimate, plot_source_spectrogram
  from mne.viz.misc import _handle_event_colors
  from mne.viz.utils import _get_color_list
label_desc: Use image node_id 7 for calling a global function with example usage: test_plot_events() without return types