code: def plot_metric_graph(
      ax: plt.Axes,
      title: str,
      graphmap: Mapping[
          str, list[float] | tuple[list[float], list[float]]
      ],
      yscale: str = "log",
      avg_keys: tuple[str] = (LOSS_NAME,),
      window_fraction: int = 20,
  ) -> None:
      """
      Plot metrics on a single graph with running averages plotted for selected keys. The values in `graphmap`
      should be lists of (timepoint, value) pairs as stored in MetricLogger objects.
  
      Args:
          ax: Axes object to plot into
          title: graph title
          graphmap: dictionary of named graph values, which are lists of values or (index, value) pairs
          yscale: scale for y-axis compatible with `Axes.set_yscale`
          avg_keys: tuple of keys in `graphmap` to provide running average plots for
          window_fraction: what fraction of the graph value length to use as the running average window
      """
      from matplotlib.ticker import MaxNLocator
  
      for n, v in graphmap.items():
          if len(v) > 0:
              if isinstance(
                  v[0], (tuple, list)
              ):  # values are (x,y) pairs
                  inds, vals = zip(
                      *v
                  )  # separate values into list of indices in X dimension and values
              else:
                  inds, vals = tuple(range(len(v))), tuple(
                      v
                  )  # values are without indices, make indices for them
  
              ax.plot(inds, vals, label=f"{n} = {vals[-1]:.5g}")
  
              # if requested compute and plot a running average for the values using a fractional window size
              if n in avg_keys and len(v) > window_fraction:
                  window = len(v) // window_fraction
                  kernel = np.ones((window,)) / window
                  ra = np.convolve(
                      (vals[0],) * (window - 1) + vals,
                      kernel,
                      mode="valid",
                  )
  
                  ax.plot(inds, ra, label=f"{n} Avg = {ra[-1]:.5g}")
  
      ax.set_title(title)
      ax.set_yscale(yscale)
      ax.axis("on")
      ax.legend(bbox_to_anchor=(1, 1), loc=1, borderaxespad=0.0)
      ax.grid(True, "both", "both")
      ax.xaxis.set_major_locator(MaxNLocator(integer=True))
  
imports: from __future__ import annotations
  import copy
  from collections.abc import Callable, Mapping
  from enum import Enum
  from threading import RLock, Thread
  from typing import TYPE_CHECKING, Any
  import numpy
  import torch
  from monai.config import IgniteInfo
  from monai.utils.module import min_version, optional_import
label_desc: Use image node_id 1 for calling a global function with example usage: plot_metric_graph(ax, title, graphmap, yscale, avg_keys, window_fraction) without return types