class_docstr: Mesher class for plotting contours of objective functions
  
  This class enables drawing a surface plot of a given objective function.
  You can customize how this plot is drawn with this class. Pass an instance
  of this class to enable meshing.
  
  .. code-block :: python
  
      from pyswarms.utils.plotters import plot_surface
      from pyswarms.utils.plotters.formatters import Mesher
      from pyswarms.utils.functions import single_obj as fx
  
      # Use sphere function
      my_mesher = Mesher(func=fx.sphere)
  
      # Assuming we already had an optimizer ready
      plot_surface(pos_history, mesher=my_mesher)
  
  Attributes
  ----------
  func : callable
      Objective function to plot a surface of.
  delta : float
      Number of steps when generating the surface plot
      Default is `0.001`
  limits : list or tuple
      The range, in each axis, where the mesh will be drawn.
      Default is :code:`[(-1,1), (-1,1)]`
  levels : list or int, optional
      Levels on which the contours are shown. If :code:`int` is passed,
      then `matplotlib` automatically computes for the level positions.
      Default is :code:`numpy.arange(-2.0, 2.0, 0.070)`
  alpha : float, optional
      Transparency of the surface plot. Default is `0.3`
  limits : list, optional
      The x-, y-, z- limits of the axes. Pass an iterable with the number of
      elements representing the number of axes. Default is :code:`[(-1, 1),
      (-1, 1)]`
docstr: Compute a 3D position matrix
  
  The first two columns are the 2D position in the x and y axes
  respectively, while the third column is the fitness on that given
  position.
  
  Parameters
  ----------
  pos_history : numpy.ndarray
      Two-dimensional position matrix history of shape
      :code:`(iterations, n_particles, 2)`
  n_processes : int
  number of processes to use for parallel mesh point calculation (default: None = no parallelization)
  
  Returns
  -------
  numpy.ndarray
      3D position matrix of shape :code:`(iterations, n_particles, 3)`
code: def compute_history_3d(self, pos_history, n_processes=None):
      """Compute a 3D position matrix
  
      The first two columns are the 2D position in the x and y axes
      respectively, while the third column is the fitness on that given
      position.
  
      Parameters
      ----------
      pos_history : numpy.ndarray
          Two-dimensional position matrix history of shape
          :code:`(iterations, n_particles, 2)`
      n_processes : int
      number of processes to use for parallel mesh point calculation (default: None = no parallelization)
  
      Returns
      -------
      numpy.ndarray
          3D position matrix of shape :code:`(iterations, n_particles, 3)`
      """
  
      # Setup Pool of processes for parallel evaluation
      pool = None if n_processes is None else mp.Pool(n_processes)
  
      if pool is None:
          fitness = np.array(list(map(self.func, pos_history)))
      else:
          iter_r = []
          # Iterate over iterations
          for i in range(len(pos_history)):
              # Parallelize particles
              r_map_split = pool.map(
                  self.func,
                  np.array_split(
                      np.array(pos_history[i]), pool._processes
                  ),
              )
              iter_r.append(np.array(np.concatenate(r_map_split)))
          fitness = np.array(iter_r)
  
      # Close Pool of Processes
      if n_processes is not None:
          pool.close()
  
      return np.dstack((pos_history, fitness))
  
file_path: pyswarms/pyswarms/utils/plotters/formatters.py
imports: import numpy
  from attr import attrib, attrs
  from attr.validators import instance_of
  from matplotlib import cm, colors
  import multiprocessing
label_desc: Use image node_id 1 for calling the Mesher obj's underlying member method code with example usage: obj.compute_history_3d(pos_history, n_processes) and returns: np