code: def test_plot_raw_psd(raw, raw_orig):
      """Test plotting of raw psds."""
      raw_unchanged = raw.copy()
      spectrum = raw.compute_psd()
      # deprecation change handler
      old_defaults = dict(picks="data", exclude="bads")
      fig = spectrum.plot(average=False, amplitude=False)
      # normal mode
      fig = spectrum.plot(
          average=False, amplitude=False, **old_defaults
      )
      fig.canvas.callbacks.process(
          "resize_event",
          backend_bases.ResizeEvent("resize_event", fig.canvas),
      )
      # specific mode
      picks = pick_types(spectrum.info, meg="mag", eeg=False)[:4]
      spectrum.plot(
          picks=picks,
          ci="range",
          spatial_colors=True,
          exclude="bads",
          amplitude=False,
      )
      raw.compute_psd(tmax=20.0).plot(
          color="yellow",
          dB=False,
          alpha=0.4,
          amplitude=True,
          **old_defaults,
      )
      plt.close("all")
      # one axes supplied
      ax = plt.axes()
      spectrum.plot(
          picks=picks,
          axes=ax,
          average=True,
          exclude="bads",
          amplitude=False,
      )
      plt.close("all")
      # two axes supplied
      _, axs = plt.subplots(2)
      spectrum.plot(
          axes=axs, average=True, amplitude=False, **old_defaults
      )
      plt.close("all")
      # need 2, got 1
      ax = plt.axes()
      with pytest.raises(
          ValueError, match="of length 2.*the length is 1"
      ):
          spectrum.plot(
              axes=ax, average=True, amplitude=False, **old_defaults
          )
      plt.close("all")
      # topo psd
      ax = plt.subplot()
      spectrum.plot_topo(axes=ax)
      plt.close("all")
      # with channel information not available
      for idx in range(len(raw.info["chs"])):
          raw.info["chs"][idx]["loc"] = np.zeros(12)
      with pytest.warns(
          RuntimeWarning, match="locations not available"
      ):
          raw.compute_psd().plot(spatial_colors=True, average=False)
      # with a flat channel
      raw[5, :] = 0
      with pytest.warns(UserWarning, match="[Infinite|Zero]"):
          spectrum = raw.compute_psd()
      for dB, amplitude in itertools.product(
          (True, False), (True, False)
      ):
          with pytest.warns(UserWarning, match="[Infinite|Zero]"):
              fig = spectrum.plot(
                  average=True, dB=dB, amplitude=amplitude
              )
          # check grad axes
          title = fig.axes[0].get_title()
          ylabel = fig.axes[0].get_ylabel()
          unit = r"fT/cm/\sqrt{Hz}" if amplitude else "(fT/cm)²/Hz"
          assert title == "Gradiometers", title
          assert unit in ylabel, ylabel
          if dB:
              assert "dB" in ylabel
          else:
              assert "dB" not in ylabel
          # check mag axes
          title = fig.axes[1].get_title()
          ylabel = fig.axes[1].get_ylabel()
          unit = r"fT/\sqrt{Hz}" if amplitude else "fT²/Hz"
          assert title == "Magnetometers", title
          assert unit in ylabel, ylabel
  
      # test xscale value checking
      raw = raw_unchanged
      spectrum = raw.compute_psd()
      with pytest.raises(
          ValueError, match="Invalid value for the 'xscale'"
      ):
          spectrum.plot(xscale="blah")
  
      # gh-5046
      raw = raw_orig.crop(0, 1)
      picks = pick_types(raw.info, meg=True)
      spectrum = raw.compute_psd(picks=picks)
      spectrum.plot(average=False, amplitude=False, **old_defaults)
      spectrum.plot(average=True, amplitude=False, **old_defaults)
      plt.close("all")
      raw.set_channel_types(
          {
              "MEG 0113": "hbo",
              "MEG 0112": "hbr",
              "MEG 0122": "fnirs_cw_amplitude",
              "MEG 0123": "fnirs_od",
          },
          verbose="error",
      )
      fig = raw.compute_psd().plot(amplitude=False, **old_defaults)
      assert len(fig.axes) == 10
      plt.close("all")
  
      # gh-7631
      n_times = sfreq = n_fft = 100
      data = 1e-3 * np.random.rand(2, n_times)
      info = create_info(
          ["CH1", "CH2"], sfreq
      )  # ch_types defaults to 'misc'
      raw = RawArray(data, info)
      picks = pick_types(raw.info, misc=True)
      spectrum = raw.compute_psd(picks=picks, n_fft=n_fft)
      spectrum.plot(
          spatial_colors=False,
          picks=picks,
          exclude="bads",
          amplitude=False,
      )
      plt.close("all")
  
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 29 for calling a global function with example usage: test_plot_raw_psd(raw, raw_orig) without return types