code: def plot_convergence(*args, **kwargs):
      """Plot one or several convergence traces.
  
      Parameters
      ----------
      args[i] :  `OptimizeResult`, list of `OptimizeResult`, or tuple
          The result(s) for which to plot the convergence trace.
  
          - if `OptimizeResult`, then draw the corresponding single trace;
          - if list of `OptimizeResult`, then draw the corresponding convergence
            traces in transparency, along with the average convergence trace;
          - if tuple, then `args[i][0]` should be a string label and `args[i][1]`
            an `OptimizeResult` or a list of `OptimizeResult`.
  
      ax : `Axes`, optional
          The matplotlib axes on which to draw the plot, or `None` to create
          a new one.
  
      true_minimum : float, optional
          The true minimum value of the function, if known.
  
      yscale : None or string, optional
          The scale for the y-axis.
  
      Returns
      -------
      ax : `Axes`
          The matplotlib axes.
      """
      # <3 legacy python
      ax = kwargs.get("ax", None)
      true_minimum = kwargs.get("true_minimum", None)
      yscale = kwargs.get("yscale", None)
  
      if ax is None:
          ax = plt.gca()
  
      ax.set_title("Convergence plot")
      ax.set_xlabel("Number of calls $n$")
      ax.set_ylabel(r"$\min f(x)$ after $n$ calls")
      ax.grid()
  
      if yscale is not None:
          ax.set_yscale(yscale)
  
      colors = cm.viridis(np.linspace(0.25, 1.0, len(args)))
  
      for results, color in zip(args, colors):
          if isinstance(results, tuple):
              name, results = results
          else:
              name = None
  
          if isinstance(results, OptimizeResult):
              n_calls = len(results.x_iters)
              mins = [
                  np.min(results.func_vals[:i])
                  for i in range(1, n_calls + 1)
              ]
              ax.plot(
                  range(1, n_calls + 1),
                  mins,
                  c=color,
                  marker=".",
                  markersize=12,
                  lw=2,
                  label=name,
              )
  
          elif isinstance(results, list):
              n_calls = len(results[0].x_iters)
              iterations = range(1, n_calls + 1)
              mins = [
                  [np.min(r.func_vals[:i]) for i in iterations]
                  for r in results
              ]
  
              for m in mins:
                  ax.plot(iterations, m, c=color, alpha=0.2)
  
              ax.plot(
                  iterations,
                  np.mean(mins, axis=0),
                  c=color,
                  marker=".",
                  markersize=12,
                  lw=2,
                  label=name,
              )
  
      if true_minimum:
          ax.axhline(
              true_minimum,
              linestyle="--",
              color="r",
              lw=1,
              label="True minimum",
          )
  
      if true_minimum or name:
          ax.legend(loc="best")
  
      return ax
  
imports: import sys
  import numpy
  from itertools import count
  from functools import partial
  from scipy.optimize import OptimizeResult
  from .acquisition import _gaussian_acquisition
  from guild._skopt import expected_minimum, expected_minimum_random_sampling
  from .space import Categorical
  from collections import Counter
  import matplotlib.pyplot
  from matplotlib.pyplot import cm
  from matplotlib.ticker import LogLocator
  from matplotlib.ticker import MaxNLocator, FuncFormatter
label_desc: Use image node_id 1 for calling a global function with example usage: plot_convergence() and returns: ax