code: def plot_chpi_snr(snr_dict, axes=None):
      """Plot time-varying SNR estimates of the HPI coils.
  
      Parameters
      ----------
      snr_dict : dict
          The dictionary returned by `~mne.chpi.compute_chpi_snr`. Must have keys
          ``times``, ``freqs``, ``TYPE_snr``, ``TYPE_power``, and ``TYPE_resid``
          (where ``TYPE`` can be ``mag`` or ``grad`` or both).
      axes : None | list of matplotlib.axes.Axes
          Figure axes in which to draw the SNR, power, and residual plots. The
          number of axes should be 3× the number of MEG sensor types present in
          ``snr_dict``. If ``None`` (the default), a new
          `~matplotlib.figure.Figure` is created with the required number of
          axes.
  
      Returns
      -------
      fig : instance of matplotlib.figure.Figure
          A figure with subplots for SNR, power, and residual variance,
          separately for magnetometers and/or gradiometers (depending on what is
          present in ``snr_dict``).
  
      Notes
      -----
      If you supply a list of existing `~matplotlib.axes.Axes`, then the figure
      legend will not be drawn automatically. If you still want it, running
      ``fig.legend(loc='right', title='cHPI frequencies')`` will recreate it.
  
      .. versionadded:: 0.24
      """
      import matplotlib.pyplot as plt
  
      valid_keys = list(snr_dict)[2:]
      titles = dict(
          snr="SNR", power="cHPI power", resid="Residual variance"
      )
      full_names = dict(mag="magnetometers", grad="gradiometers")
      axes_was_none = axes is None
      if axes_was_none:
          fig, axes = plt.subplots(
              len(valid_keys), 1, sharex=True, layout="constrained"
          )
      else:
          fig = axes[0].get_figure()
      if len(axes) != len(valid_keys):
          raise ValueError(
              f"axes must be a list of {len(valid_keys)} axes, got "
              f"length {len(axes)} ({axes})."
          )
      fig.set_size_inches(10, 10)
      legend_labels_exist = False
      for key, ax in zip(valid_keys, axes):
          ch_type, kind = key.split("_")
          scaling = (
              1 if kind == "snr" else DEFAULTS["scalings"][ch_type]
          )
          plot_kwargs = dict(color="k") if kind == "resid" else dict()
          lines = ax.plot(
              snr_dict["times"],
              snr_dict[key] * scaling**2,
              **plot_kwargs,
          )
          # the freqs should be the same for all sensor types (and for SNR and
          # power subplots), so we only need to label the lines on one axes
          # (otherwise we get duplicate legend entries).
          if not legend_labels_exist:
              for line, freq in zip(lines, snr_dict["freqs"]):
                  line.set_label(f"{freq} Hz")
              legend_labels_exist = True
          unit = DEFAULTS["units"][ch_type]
          unit = f"({unit})" if "/" in unit else unit
          set_kwargs = dict(
              title=f"{titles[kind]}, {full_names[ch_type]}",
              ylabel="dB" if kind == "snr" else f"{unit}²",
          )
          if not axes_was_none:
              set_kwargs.update(xlabel="Time (s)")
          ax.set(**set_kwargs)
      if axes_was_none:
          ax.set(xlabel="Time (s)")
          fig.align_ylabels()
          fig.legend(loc="right", title="cHPI frequencies")
      return fig
  
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 18 for calling a global function with example usage: plot_chpi_snr(snr_dict, axes) and returns: fig