code: def plot_cost_history(
      cost_history,
      ax=None,
      title="Cost History",
      designer=None,
      **kwargs,
  ):
      """Create a simple line plot with the cost in the y-axis and
      the iteration at the x-axis
  
      Parameters
      ----------
      cost_history : array_like
          Cost history of shape :code:`(iters, )` or length :code:`iters` where
          each element contains the cost for the given iteration.
      ax : :obj:`matplotlib.axes.Axes`, optional
          The axes where the plot is to be drawn. If :code:`None` is
          passed, then the plot will be drawn to a new set of axes.
      title : str, optional
          The title of the plotted graph. Default is `Cost History`
      designer : :obj:`pyswarms.utils.formatters.Designer`, optional
          Designer class for custom attributes
      **kwargs : dict
          Keyword arguments that are passed as a keyword argument to
          :class:`matplotlib.axes.Axes`
  
      Returns
      -------
      :obj:`matplotlib.axes._subplots.AxesSubplot`
          The axes on which the plot was drawn.
      """
      try:
          # Infer number of iterations based on the length
          # of the passed array
          iters = len(cost_history)
  
          # If no Designer class supplied, use defaults
          if designer is None:
              designer = Designer(
                  legend="Cost", label=["Iterations", "Cost"]
              )
  
          # If no ax supplied, create new instance
          if ax is None:
              _, ax = plt.subplots(1, 1, figsize=designer.figsize)
  
          # Plot with iters in x-axis and the cost in y-axis
          ax.plot(
              np.arange(iters),
              cost_history,
              "k",
              lw=2,
              label=designer.legend,
          )
  
          # Customize plot depending on parameters
          ax.set_title(title, fontsize=designer.title_fontsize)
          ax.legend(fontsize=designer.text_fontsize)
          ax.set_xlabel(
              designer.label[0], fontsize=designer.text_fontsize
          )
          ax.set_ylabel(
              designer.label[1], fontsize=designer.text_fontsize
          )
          ax.tick_params(labelsize=designer.text_fontsize)
      except TypeError:
          rep.logger.exception("Please check your input type")
          raise
      else:
          return ax
  
file_path: pyswarms/pyswarms/utils/plotters/plotters.py
imports: import logging
  import matplotlib.pyplot
  import numpy
  import multiprocessing
  from matplotlib import animation, cm
  from mpl_toolkits.mplot3d import Axes3D
  from ..reporter import Reporter
  from .formatters import Animator, Designer
label_desc: Use image node_id 1 for calling a global function with example usage: plot_cost_history(cost_history, ax, title, designer) and returns: ax