code: def evolve_visual(msnake, fig=None, levelset=None, num_iters=20, background=None):
      
      if levelset is not None:
          msnake.levelset = levelset
      
      # Prepare the visual environment.
      if fig is None:
          fig = plt.figure()
      fig.clf()
      ax1 = fig.add_subplot(1, 2, 1)
      if background is None:
          ax1.imshow(msnake.data, cmap=plt.cm.gray)
      else:
          ax1.imshow(background, cmap=plt.cm.gray)
      ax1.contour(msnake.levelset, [0.5], colors='r')
      
      ax2 = fig.add_subplot(1, 2, 2)
      ax_u = ax2.imshow(msnake.levelset)
      plt.pause(0.001)
      
      # Iterate.
      for _ in range(num_iters):
          # Evolve.
          msnake.step()
          
          # Update figure.
          del ax1.collections[0]
          ax1.contour(msnake.levelset, [0.5], colors='r')
          ax_u.set_data(msnake.levelset)
          fig.canvas.draw()
          #plt.pause(0.001)
      
      # Return the last levelset.
      return msnake.levelset
docs: Visual evolution of a morphological snake.
      
      Parameters
      ----------
      msnake : MorphGAC or MorphACWE instance
          The morphological snake solver.
      fig: object, optional
          Handles to actual figure.
      levelset : array-like, optional
          If given, the levelset of the solver is initialized to this. If not
          given, the evolution will use the levelset already set in msnake.
      num_iters : int, optional
          The number of iterations.
      background : array-like, optional
          If given, background will be shown behind the contours instead of
          msnake.data.