code: def test_plot_topomap_basic():
      """Test basics of topomap plotting."""
      evoked = read_evokeds(
          evoked_fname, "Left Auditory", baseline=(None, 0)
      )
      res = 8
      fast_test_noscale = dict(res=res, contours=0, sensors=False)
      ev_bad = evoked.copy().pick(picks="eeg")
      ev_bad.pick(ev_bad.ch_names[:2])
      plt_topomap = partial(ev_bad.plot_topomap, **fast_test)
      plt_topomap(times=ev_bad.times[:2] - 1e-6)  # auto, plots EEG
      evoked.plot_topomap(
          [0.1],
          ch_type="eeg",
          scalings=1,
          res=res,
          contours=[-100, 0, 100],
          time_unit="ms",
      )
  
      # test channel placement when only 'grad' are picked:
      # ---------------------------------------------------
      info_grad = evoked.copy().pick("grad").info
      n_grads = len(info_grad["ch_names"])
      data = np.random.randn(n_grads)
      img, _ = plot_topomap(data, info_grad)
  
      # check that channels are scattered around x == 0
      pos = img.axes.collections[-1].get_offsets()
      prop_channels_on_the_right = (pos[:, 0] > 0).mean()
      assert prop_channels_on_the_right < 0.6
  
      # other:
      # ------
      plt_topomap = partial(evoked.plot_topomap, **fast_test)
      plt.close("all")
      axes = [plt.subplot(221), plt.subplot(222)]
      plt_topomap(axes=axes, colorbar=False)
      plt.close("all")
      plt_topomap(times=[-0.1, 0.2])
      plt.close("all")
      evoked_grad = evoked.copy().crop(0, 0).pick(picks="grad")
      mask = np.zeros((204, 1), bool)
      mask[[0, 3, 5, 6]] = True
      names = []
  
      def proc_names(x):
          names.append(x)
          return x[4:]
  
      evoked_grad.plot_topomap(
          ch_type="grad",
          times=[0],
          mask=mask,
          show_names=proc_names,
          **fast_test,
      )
      want_names = np.array(evoked_grad.ch_names)[
          mask.squeeze()
      ].tolist()
      assert_equal(
          [f"{name[:-1]}x" for name in want_names],
          ["MEG 011x", "MEG 012x", "MEG 013x", "MEG 014x"],
      )
      mask = np.zeros_like(evoked.data, dtype=bool)
      mask[[1, 5], :] = True
      plt_topomap(ch_type="mag", outlines=None)
      times = [0.1]
      plt_topomap(times, ch_type="grad", mask=mask)
      plt_topomap(times, ch_type="planar1")
      plt_topomap(times, ch_type="planar2")
      plt_topomap(
          times,
          ch_type="grad",
          mask=mask,
          show_names=True,
          mask_params={"marker": "x"},
      )
      plt.close("all")
  
      p = plt_topomap(
          times,
          ch_type="grad",
          image_interp="cubic",
          show_names=lambda x: x.replace("MEG", ""),
      )
      subplot = [
          x
          for x in p.get_children()
          if any(t in str(type(x)) for t in ("Axes", "Subplot"))
      ]
      assert len(subplot) >= 1, [type(x) for x in p.get_children()]
      subplot = subplot[0]
  
      have_all = all(
          "MEG" not in x.get_text()
          for x in subplot.get_children()
          if isinstance(x, matplotlib.text.Text)
      )
      assert have_all
  
      # Plot array
      for ch_type in ("mag", "grad"):
          evoked_ = evoked.copy().pick(picks=ch_type)
          plot_topomap(
              evoked_.data[:, 0], evoked_.info, **fast_test_noscale
          )
      # fail with multiple channel types
      pytest.raises(
          ValueError, plot_topomap, evoked.data[0, :], evoked.info
      )
  
      # Test title
      def get_texts(p):
          return [
              x.get_text()
              for x in p.get_children()
              if isinstance(x, matplotlib.text.Text)
          ]
  
      p = plt_topomap(times, ch_type="eeg", average=0.01)
      assert_equal(len(get_texts(p)), 0)
      plt.close("all")
  
      # Test averaging with a scalar input
      averaging_times = [ev_bad.times[0], times[0], ev_bad.times[-1]]
      p = plt_topomap(averaging_times, ch_type="eeg", average=0.01)
  
      expected_ax_titles = (
          "-0.200 – -0.195 s",  # clipped on the left
          "0.095 – 0.105 s",  # full range
          "0.494 – 0.499 s",  # clipped on the right
      )
      for idx, expected_title in enumerate(expected_ax_titles):
          assert p.axes[idx].get_title() == expected_title
  
      # Test averaging with an array-like input
      averaging_durations = [0.01, 0.02, None]
      p = plt_topomap(
          averaging_times, ch_type="eeg", average=averaging_durations
      )
      expected_ax_titles = (
          "-0.200 – -0.195 s",  # clipped on the left
          "0.090 – 0.110 s",  # full range
          "0.499 s",  # No averaging
      )
      for idx, expected_title in enumerate(expected_ax_titles):
          assert p.axes[idx].get_title() == expected_title
  
      del averaging_times, expected_ax_titles, expected_title
  
      # delaunay triangulation warning
      plt_topomap(times, ch_type="mag")
  
      # change to no-proj mode
      evoked = read_evokeds(
          evoked_fname, "Left Auditory", baseline=(None, 0), proj=False
      )
      plt.close("all")
      fig1 = evoked.plot_topomap(
          "interactive", ch_type="mag", proj="interactive", **fast_test
      )
      # TODO: Clicking the slider creates a *new* image rather than updating
      # the data directly. This makes it so that the projection is not applied
      # to the correct matplotlib Image object.
      # _fake_click(fig1, fig1.axes[1], (0.5, 0.5))  # click slider
      data_max = np.max(fig1.axes[0].images[0]._A)
      proj_fig = plt.figure(plt.get_fignums()[-1])
      assert fig1.mne.proj_checkboxes.get_status() == [
          False,
          False,
          False,
      ]
      pos = proj_fig.axes[0].texts[0].get_position() + np.array(
          [0.01, 0]
      )
      _fake_click(proj_fig, proj_fig.axes[0], pos)  # toggle projector
      # make sure projector gets toggled
      assert fig1.mne.proj_checkboxes.get_status() == [
          True,
          False,
          False,
      ]
      assert np.max(fig1.axes[0].images[0]._A) != data_max
  
      for ch in evoked.info["chs"]:
          if ch["coil_type"] == FIFF.FIFFV_COIL_EEG:
              ch["loc"].fill(0)
  
      # Remove extra digitization point, so EEG digitization points
      # correspond with the EEG electrodes
      del evoked.info["dig"][85]
  
      # Pass custom outlines without patch
      eeg_picks = pick_types(evoked.info, meg=False, eeg=True)
      pos, outlines = _get_pos_outlines(evoked.info, eeg_picks, 0.1)
      evoked.plot_topomap(
          times, ch_type="eeg", outlines=outlines, **fast_test
      )
      plt.close("all")
  
      # Test interactive cmap
      fig = plot_evoked_topomap(
          evoked,
          times=[0.0, 0.1],
          ch_type="eeg",
          cmap=("Reds", True),
          **fast_test,
      )
      _fake_keypress(fig, "up")
      _fake_keypress(fig, " ")
      _fake_keypress(fig, "down")
      cbar = fig.get_axes()[0].CB  # Fake dragging with mouse.
      ax = cbar.cbar.ax
      _fake_click(fig, ax, (0.1, 0.1))
      _fake_click(fig, ax, (0.1, 0.2), kind="motion")
      _fake_click(fig, ax, (0.1, 0.3), kind="release")
  
      _fake_click(fig, ax, (0.1, 0.1), button=3)
      _fake_click(fig, ax, (0.1, 0.2), button=3, kind="motion")
      _fake_click(fig, ax, (0.1, 0.3), kind="release")
  
      _fake_scroll(fig, 0.5, 0.5, -0.5)  # scroll down
      _fake_scroll(fig, 0.5, 0.5, 0.5)  # scroll up
  
      plt.close("all")
  
      # Pass custom outlines with patch callable
      def patch():
          return Circle(
              (0.5, 0.4687),
              radius=0.46,
              clip_on=True,
              transform=plt.gca().transAxes,
          )
  
      outlines["patch"] = patch
      plot_evoked_topomap(
          evoked, times, ch_type="eeg", outlines=outlines, **fast_test
      )
  
      # Test error messages for invalid pos parameter
      n_channels = len(pos)
      data = np.ones(n_channels)
      pos_1d = np.zeros(n_channels)
      pos_3d = np.zeros((n_channels, 2, 2))
      pytest.raises(ValueError, plot_topomap, data, pos_1d)
      pytest.raises(ValueError, plot_topomap, data, pos_3d)
      pytest.raises(ValueError, plot_topomap, data, pos[:3, :])
  
      pos_x = pos[:, :1]
      pos_xyz = np.c_[pos, np.zeros(n_channels)[:, np.newaxis]]
      pytest.raises(ValueError, plot_topomap, data, pos_x)
      pytest.raises(ValueError, plot_topomap, data, pos_xyz)
  
      # An #channels x 4 matrix should work though. In this case (x, y, width,
      # height) is assumed.
      pos_xywh = np.c_[pos, np.zeros((n_channels, 2))]
      plot_topomap(data, pos_xywh)
      plt.close("all")
  
      # Test peak finder
      axes = [plt.subplot(131), plt.subplot(132)]
      evoked.plot_topomap(times="peaks", axes=axes, **fast_test)
      plt.close("all")
      evoked.data = np.zeros(evoked.data.shape)
      evoked.data[50][1] = 1
      assert_array_equal(_find_peaks(evoked, 10), evoked.times[1])
      evoked.data[80][100] = 1
      assert_array_equal(
          _find_peaks(evoked, 10), evoked.times[[1, 100]]
      )
      evoked.data[2][95] = 2
      assert_array_equal(_find_peaks(evoked, 10), evoked.times[[1, 95]])
      assert_array_equal(_find_peaks(evoked, 1), evoked.times[95])
  
      # Test excluding bads channels
      evoked_grad.info["bads"] += [evoked_grad.info["ch_names"][0]]
      orig_bads = evoked_grad.info["bads"]
      evoked_grad.plot_topomap(
          ch_type="grad", times=[0], time_unit="ms"
      )
      assert_array_equal(evoked_grad.info["bads"], orig_bads)
      plt.close("all")
  
imports: from functools import partial
  from pathlib import Path
  import matplotlib
  import matplotlib.pyplot
  import numpy
  import pytest
  from matplotlib.patches import Circle
  from numpy.testing import assert_almost_equal, assert_array_equal, assert_equal
  from mne import Epochs, EvokedArray, Projection, compute_proj_evoked, compute_proj_raw, create_info, find_layout, make_fixed_length_events, pick_types, read_cov, read_evokeds, read_proj
  from mne._fiff.compensator import get_current_comp
  from mne._fiff.constants import FIFF
  from mne._fiff.pick import _picks_to_idx, channel_indices_by_type, pick_info
  from mne._fiff.proj import make_eeg_average_ref_proj
  from mne.channels import find_ch_adjacency, make_dig_montage, make_standard_montage, read_layout
  from mne.datasets import testing
  from mne.io import RawArray, read_info, read_raw_fif
  from mne.preprocessing import compute_bridged_electrodes
  from mne.time_frequency.tfr import AverageTFR
  from mne.viz import plot_evoked_topomap, plot_projs_topomap, topomap
  from mne.viz.tests.test_raw import _proj_status
  from mne.viz.topomap import _get_pos_outlines, _onselect, plot_arrowmap, plot_bridged_electrodes, plot_ch_adjacency, plot_psds_topomap, plot_topomap
  from mne.viz.utils import _fake_click, _fake_keypress, _fake_scroll, _find_peaks
label_desc: Use image node_id 10 for calling a global function with example usage: test_plot_topomap_basic() and returns: x, unknown, Circle