code: def plot_csd(
      csd,
      info=None,
      mode="csd",
      colorbar=True,
      cmap=None,
      n_cols=None,
      show=True,
  ):
      """Plot CSD matrices.
  
      A sub-plot is created for each frequency. If an info object is passed to
      the function, different channel types are plotted in different figures.
  
      Parameters
      ----------
      csd : instance of CrossSpectralDensity
          The CSD matrix to plot.
      %(info)s
          Used to split the figure by channel-type, if provided.
          By default, the CSD matrix is plotted as a whole.
      mode : 'csd' | 'coh'
          Whether to plot the cross-spectral density ('csd', the default), or
          the coherence ('coh') between the channels.
      colorbar : bool
          Whether to show a colorbar. Defaults to ``True``.
      cmap : str | None
          The matplotlib colormap to use. Defaults to None, which means the
          colormap will default to matplotlib's default.
      n_cols : int | None
          CSD matrices are plotted in a grid. This parameter controls how
          many matrix to plot side by side before starting a new row. By
          default, a number will be chosen to make the grid as square as
          possible.
      show : bool
          Whether to show the figure. Defaults to ``True``.
  
      Returns
      -------
      fig : list of Figure
          The figures created by this function.
      """
      import matplotlib.pyplot as plt
  
      if mode not in ["csd", "coh"]:
          raise ValueError('"mode" should be either "csd" or "coh".')
  
      if info is not None:
          info_ch_names = info["ch_names"]
          sel_eeg = pick_types(
              info, meg=False, eeg=True, ref_meg=False, exclude=[]
          )
          sel_mag = pick_types(
              info, meg="mag", eeg=False, ref_meg=False, exclude=[]
          )
          sel_grad = pick_types(
              info, meg="grad", eeg=False, ref_meg=False, exclude=[]
          )
          idx_eeg = [
              csd.ch_names.index(info_ch_names[c])
              for c in sel_eeg
              if info_ch_names[c] in csd.ch_names
          ]
          idx_mag = [
              csd.ch_names.index(info_ch_names[c])
              for c in sel_mag
              if info_ch_names[c] in csd.ch_names
          ]
          idx_grad = [
              csd.ch_names.index(info_ch_names[c])
              for c in sel_grad
              if info_ch_names[c] in csd.ch_names
          ]
          indices = [idx_eeg, idx_mag, idx_grad]
          titles = ["EEG", "Magnetometers", "Gradiometers"]
  
          if mode == "csd":
              # The units in which to plot the CSD
              units = dict(eeg="µV²", grad="fT²/cm²", mag="fT²")
              scalings = dict(eeg=1e12, grad=1e26, mag=1e30)
      else:
          indices = [np.arange(len(csd.ch_names))]
          if mode == "csd":
              titles = ["Cross-spectral density"]
              # Units and scaling unknown
              units = dict()
              scalings = dict()
          elif mode == "coh":
              titles = ["Coherence"]
  
      n_freqs = len(csd.frequencies)
  
      if n_cols is None:
          n_cols = int(np.ceil(np.sqrt(n_freqs)))
      n_rows = int(np.ceil(n_freqs / float(n_cols)))
  
      figs = []
      for ind, title, ch_type in zip(
          indices, titles, ["eeg", "mag", "grad"]
      ):
          if len(ind) == 0:
              continue
  
          fig, axes = plt.subplots(
              n_rows,
              n_cols,
              squeeze=False,
              figsize=(2 * n_cols + 1, 2.2 * n_rows),
              layout="constrained",
          )
  
          csd_mats = []
          for i in range(len(csd.frequencies)):
              cm = csd.get_data(index=i)[ind][:, ind]
              if mode == "csd":
                  cm = np.abs(cm) * scalings.get(ch_type, 1)
              elif mode == "coh":
                  # Compute coherence from the CSD matrix
                  psd = np.diag(cm).real
                  cm = (
                      np.abs(cm) ** 2
                      / psd[np.newaxis, :]
                      / psd[:, np.newaxis]
                  )
              csd_mats.append(cm)
  
          vmax = np.max(csd_mats)
  
          for i, (freq, mat) in enumerate(
              zip(csd.frequencies, csd_mats)
          ):
              ax = axes[i // n_cols][i % n_cols]
              im = ax.imshow(
                  mat,
                  interpolation="nearest",
                  cmap=cmap,
                  vmin=0,
                  vmax=vmax,
              )
              ax.set_xticks([])
              ax.set_yticks([])
              if csd._is_sum:
                  ax.set_title(
                      "%.1f-%.1f Hz." % (np.min(freq), np.max(freq))
                  )
              else:
                  ax.set_title("%.1f Hz." % freq)
  
          plt.suptitle(title)
          if colorbar:
              cb = plt.colorbar(im, ax=[a for ax_ in axes for a in ax_])
              if mode == "csd":
                  label = "CSD"
                  if ch_type in units:
                      label += " (%s)" % units[ch_type]
                  cb.set_label(label)
              elif mode == "coh":
                  cb.set_label("Coherence")
  
          figs.append(fig)
  
      plt_show(show)
      return figs
  
imports: import copy
  import io
  import os
  import os.path
  import warnings
  from collections import defaultdict
  from glob import glob
  from itertools import cycle
  from pathlib import Path
  import numpy
  from scipy.signal import filtfilt, freqz, group_delay, lfilter, sosfilt, sosfiltfilt
  from .._fiff.constants import FIFF
  from .._fiff.pick import _DATA_CH_TYPES_SPLIT, _picks_by_type, pick_channels, pick_info, pick_types
  from .._fiff.proj import make_projector
  from .._freesurfer import _check_mri, _mri_orientation, _read_mri_info, _reorient_image
  from ..defaults import DEFAULTS
  from ..filter import estimate_ringing_samples
  from ..fixes import _safe_svd
  from ..rank import compute_rank
  from ..surface import read_surface
  from ..transforms import _frame_to_str, apply_trans
  from ..utils import _check_option, _mask_to_onsets_offsets, _on_missing, _pl, fill_doc, get_subjects_dir, logger, verbose, warn
  from .utils import _figure_agg, _get_color_list, _prepare_trellis, _validate_type, plt_show
label_desc: Use image node_id 17 for calling a global function with example usage: plot_csd(csd, info, mode, colorbar, cmap, n_cols, show) and returns: figs