code: def test_plot_raw_selection(raw, browser_backend):
      """Test selection mode of plot_raw()."""
      ismpl = browser_backend.name == "matplotlib"
      with raw.info._unlock():
          raw.info[
              "lowpass"
          ] = 10.0  # allow heavy decim during plotting
      browser_backend._close_all()  # ensure all are closed
      assert browser_backend._get_n_figs() == 0
      fig = raw.plot(group_by="selection", proj=False)
      assert browser_backend._get_n_figs() == 2
      sel_fig = fig.mne.fig_selection
      assert sel_fig is not None
      # test changing selection with arrow keys
      left_temp = "Left-temporal"
      sel_dict = fig.mne.ch_selections
      assert len(fig.mne.traces) == len(sel_dict[left_temp])  # 6
      fig._fake_keypress("down", fig=sel_fig)
      assert len(fig.mne.traces) == len(sel_dict["Left-frontal"])  # 3
      fig._fake_keypress("down", fig=sel_fig)
      assert len(fig.mne.traces) == len(sel_dict["Misc"])  # 1
      fig._fake_keypress(
          "down", fig=sel_fig
      )  # ignored; no custom sel defined
      assert len(fig.mne.traces) == len(sel_dict["Misc"])  # 1
      # switch to butterfly mode
      fig._fake_keypress("b", fig=sel_fig)
  
      # ToDo: For Qt-backend the framework around RawTraceItem makes
      #  it difficult to show the same channel multiple times which is why
      #  it is currently not implemented.
      #  This would be relevant if you wanted to plot several selections in
      #  butterfly-mode which have some channels in common.
      sel_picks = len(np.concatenate(list(sel_dict.values())))
      if ismpl:
          assert len(fig.mne.traces) == sel_picks
      else:
          assert len(fig.mne.traces) == sel_picks - 1
      assert fig.mne.butterfly
      # test clicking on radio buttons → should cancel butterfly mode
      if ismpl:
          print(f"Clicking button: {repr(left_temp)}")
          assert (
              sel_fig.mne.radio_ax.buttons.labels[0].get_text()
              == left_temp
          )
          xy = _get_button_xy(sel_fig.mne.radio_ax.buttons, 0)
          lim = sel_fig.mne.radio_ax.get_xlim()
          assert lim[0] < xy[0] < lim[1]
          lim = sel_fig.mne.radio_ax.get_ylim()
          assert lim[0] < xy[1] < lim[1]
          fig._fake_click(
              xy, fig=sel_fig, ax=sel_fig.mne.radio_ax, xform="data"
          )
      else:
          # For an unknown reason test-clicking on checkboxes is inconsistent
          # across platforms.
          # (QTest.mouseClick works isolated on all platforms but somehow
          # not in this context. _fake_click isn't working on linux)
          sel_fig._chkbx_changed(list(sel_fig.chkbxs.keys())[0])
      assert not fig.mne.butterfly
      assert len(fig.mne.traces) == len(sel_dict[left_temp])  # 6
      # test clicking on "custom" when not defined: should be no-op
      if ismpl:
          before_state = sel_fig.mne.radio_ax.buttons.value_selected
          xy = _get_button_xy(sel_fig.mne.radio_ax.buttons, -1)
          fig._fake_click(
              xy, fig=sel_fig, ax=sel_fig.mne.radio_ax, xform="data"
          )
          lasso = sel_fig.lasso
          sensor_ax = sel_fig.mne.sensor_ax
          assert (
              sel_fig.mne.radio_ax.buttons.value_selected
              == before_state
          )
      else:
          before_state = sel_fig.mne.old_selection
          chkbx = sel_fig.chkbxs[list(sel_fig.chkbxs.keys())[-1]]
          fig._fake_click((0.5, 0.5), fig=chkbx)
          lasso = sel_fig.channel_fig.lasso
          sensor_ax = sel_fig.channel_widget
          assert before_state == sel_fig.mne.old_selection  # unchanged
      assert len(fig.mne.traces) == len(
          sel_dict[left_temp]
      )  # unchanged
      # test marking bad channel in selection mode → should make sensor red
      assert lasso.ec[:, 0].sum() == 0  # R of RGBA zero for all chans
      fig._click_ch_name(ch_index=1, button=1)  # mark bad
      assert lasso.ec[:, 0].sum() == 1  # one channel red
      fig._click_ch_name(ch_index=1, button=1)  # mark good
      assert lasso.ec[:, 0].sum() == 0  # all channels black
      # test lasso
      # Testing lasso-interactivity of sensor-plot within Qt-backend
      # with QTest doesn't seem to work.
      want = [
          "MEG 0111",
          "MEG 0112",
          "MEG 0113",
          "MEG 0131",
          "MEG 0132",
          "MEG 0133",
      ]
      assert want == sorted(fig.mne.ch_names[fig.mne.picks])
      want = ["MEG 0121", "MEG 0122", "MEG 0123"]
      if ismpl:
          sel_fig._set_custom_selection()  # lasso empty → should do nothing
          # Lasso with 1 mag/grad sensor unit (upper left)
          fig._fake_click(
              (0, 1),
              add_points=[(0.65, 1), (0.65, 0.7), (0, 0.7)],
              fig=sel_fig,
              ax=sensor_ax,
              xform="ax",
              kind="drag",
          )
      else:
          lasso.selection = want
          sel_fig._set_custom_selection()
      assert sorted(want) == sorted(fig.mne.ch_names[fig.mne.picks])
      # test joint closing of selection & data windows
      fig._fake_keypress(sel_fig.mne.close_key, fig=sel_fig)
      fig._close_event(sel_fig)
      assert browser_backend._get_n_figs() == 0
  
imports: import itertools
  import os
  from copy import deepcopy
  import matplotlib.pyplot
  import numpy
  import pytest
  from matplotlib import backend_bases
  from numpy.testing import assert_allclose
  from mne import Annotations, create_info, pick_types
  from mne._fiff.pick import _DATA_CH_TYPES_ORDER_DEFAULT, _PICK_TYPES_DATA_DICT
  from mne.annotations import _sync_onset
  from mne.datasets import testing
  from mne.io import RawArray
  from mne.utils import _assert_no_instances, _dt_to_stamp, _record_warnings, check_version, get_config, set_config
  from mne.viz import plot_raw, plot_sensors
  from mne.viz.utils import _fake_click, _fake_keypress
label_desc: Use image node_id 11 for calling a global function with example usage: test_plot_raw_selection(raw, browser_backend) without return types