code: def test_plot_evoked():
      """Test evoked.plot."""
      epochs = _get_epochs()
      evoked = epochs.average()
      assert evoked.proj is False
      fig = evoked.plot(
          proj=True,
          hline=[1],
          exclude=[],
          window_title="foo",
          time_unit="s",
      )
      amplitudes = _get_amplitudes(fig)
      assert len(amplitudes) == len(default_picks)
      assert evoked.proj is False
      assert evoked.info["bads"] == ["MEG 2641", "EEG 004"]
      eeg_lines = fig.axes[2].lines
      n_eeg = sum(
          ch_type == "eeg" for ch_type in evoked.get_channel_types()
      )
      assert len(eeg_lines) == n_eeg == 4
      n_bad = sum(
          same_color(line.get_color(), "0.5") for line in eeg_lines
      )
      assert n_bad == 1
      # Test a click
      ax = fig.get_axes()[0]
      line = ax.lines[0]
      _fake_click(
          fig, ax, [line.get_xdata()[0], line.get_ydata()[0]], "data"
      )
      _fake_click(fig, ax, [ax.get_xlim()[0], ax.get_ylim()[1]], "data")
      # plot with bad channels excluded & spatial_colors & zorder
      evoked.plot(exclude="bads", time_unit="s")
  
      # test selective updating of dict keys is working.
      evoked.plot(hline=[1], units=dict(mag="femto foo"), time_unit="s")
      evoked_delayed_ssp = _get_epochs_delayed_ssp().average()
      evoked_delayed_ssp.plot(proj="interactive", time_unit="s")
      evoked_delayed_ssp.apply_proj()
      pytest.raises(
          RuntimeError,
          evoked_delayed_ssp.plot,
          proj="interactive",
          time_unit="s",
      )
      with evoked_delayed_ssp.info._unlock():
          evoked_delayed_ssp.info["projs"] = []
      pytest.raises(
          RuntimeError,
          evoked_delayed_ssp.plot,
          proj="interactive",
          time_unit="s",
      )
      pytest.raises(
          RuntimeError,
          evoked_delayed_ssp.plot,
          proj="interactive",
          axes="foo",
          time_unit="s",
      )
      plt.close("all")
  
      # test `gfp='only'`: GFP (EEG) and RMS (MEG)
      fig, ax = plt.subplots(3)
      evoked.plot(gfp="only", time_unit="s", axes=ax)
  
      assert (
          len(ax[0].lines) == len(ax[1].lines) == len(ax[2].lines) == 1
      )
  
      assert ax[0].get_title() == "EEG (3 channels)"
      assert ax[0].texts[0].get_text() == "GFP"
  
      assert ax[1].get_title() == "Gradiometers (9 channels)"
      assert ax[1].texts[0].get_text() == "RMS"
  
      assert ax[2].get_title() == "Magnetometers (2 channels)"
      assert ax[1].texts[0].get_text() == "RMS"
  
      plt.close("all")
  
      # Test invalid `gfp`
      with pytest.raises(ValueError):
          evoked.plot(gfp="foo", time_unit="s")
  
      # plot with bad channels excluded, spatial_colors, zorder & pos. layout
      evoked.rename_channels({"MEG 0133": "MEG 0000"})
      evoked.plot(
          exclude=evoked.info["bads"],
          spatial_colors=True,
          gfp=True,
          zorder="std",
          time_unit="s",
      )
      evoked.plot(
          exclude=[],
          spatial_colors=True,
          zorder="unsorted",
          time_unit="s",
      )
      pytest.raises(
          TypeError, evoked.plot, zorder="asdf", time_unit="s"
      )
      plt.close("all")
  
      evoked.plot_sensors()  # Test plot_sensors
      plt.close("all")
  
      evoked.pick(evoked.ch_names[:4])
      with catch_logging() as log_file:
          evoked.plot(verbose=True, time_unit="s")
      assert "Need more than one" in log_file.getvalue()
  
      # Test highlight
      for highlight in [(0, 0.1), [(0, 0.1), (0.1, 0.2)]]:
          fig = evoked.plot(time_unit="s", highlight=highlight)
          regular_axes = [
              ax for ax in fig.axes if not isinstance(ax, HostAxes)
          ]
          for ax in regular_axes:
              highlighted_areas = [
                  child
                  for child in ax.get_children()
                  if isinstance(child, PolyCollection)
              ]
              assert len(highlighted_areas) == len(
                  np.atleast_2d(highlight)
              )
  
      with pytest.raises(
          ValueError, match="must be reshapable into a 2D array"
      ):
          fig = evoked.plot(time_unit="s", highlight=0.1)
  
      # set one channel location to nan, confirm spatial_colors still works
      evoked = _get_epochs().load_data().average("grad")  # reload data
      evoked.info["chs"][0]["loc"][:] = np.nan
      fig = evoked.plot(time_unit="s", spatial_colors=True)
      line_clr = [x.get_color() for x in fig.axes[0].get_lines()]
      assert not np.all(np.isnan(line_clr) & (line_clr == 0))
  
imports: from pathlib import Path
  import matplotlib.pyplot
  import numpy
  import pytest
  from matplotlib import gridspec
  from matplotlib.collections import PolyCollection
  from matplotlib.colors import same_color
  from mpl_toolkits.axes_grid1.parasite_axes import HostAxes
  from numpy.testing import assert_allclose
  import mne
  from mne import Epochs, compute_covariance, compute_proj_evoked, make_fixed_length_events, read_cov, read_events
  from mne._fiff.constants import FIFF
  from mne.datasets import testing
  from mne.io import read_raw_fif
  from mne.stats.parametric import _parametric_ci
  from mne.utils import catch_logging
  from mne.viz import plot_compare_evokeds, plot_evoked_white
  from mne.viz.utils import _fake_click, _get_cmap
label_desc: Use image node_id 4 for calling a global function with example usage: test_plot_evoked() without return types