code: def plot_img_on_surf(
      stat_map,
      surf_mesh="fsaverage5",
      mask_img=None,
      hemispheres=["left", "right"],
      bg_on_data=False,
      inflate=False,
      views=["lateral", "medial"],
      output_file=None,
      title=None,
      colorbar=True,
      vmin=None,
      vmax=None,
      threshold=None,
      symmetric_cbar="auto",
      cmap="cold_hot",
      cbar_tick_format="%i",
      **kwargs,
  ):
      """Plot multiple views of plot_surf_stat_map \
      in a single figure.
  
      It projects stat_map into meshes and plots views of
      left and right hemispheres. The *views* argument defines the views
      that are shown. This function returns the fig, axes elements from
      matplotlib unless kwargs sets and output_file, in which case nothing
      is returned.
  
      Parameters
      ----------
      stat_map : str or 3D Niimg-like object
          See :ref:`extracting_data`.
  
      surf_mesh : str, dict, or None, default='fsaverage5'
          If str, either one of the two:
          'fsaverage5': the low-resolution fsaverage5 :term:`mesh` (10242 nodes)
          'fsaverage': the high-resolution fsaverage :term:`mesh` (163842 nodes)
          If dict, a dictionary with keys: ['infl_left', 'infl_right',
          'pial_left', 'pial_right', 'sulc_left', 'sulc_right'], where
          values are surface :term:`mesh` geometries as accepted
          by plot_surf_stat_map.
  
      mask_img : Niimg-like object or None, optional
          The mask is passed to vol_to_surf.
          Samples falling out of this mask or out of the image are ignored
          during projection of the volume to the surface.
          If ``None``, don't apply any mask.
  
      %(bg_on_data)s
  
      hemispheres : :obj:`list` of :obj:`str`, default=["left", "right"]
          Hemispheres to display.
  
      inflate : bool, default=False
          If True, display images in inflated brain.
          If False, display images in pial surface.
  
      views : list of strings, default=['lateral', 'medial']
          A list containing all views to display.
          The montage will contain as many rows as views specified by
          display mode. Order is preserved, and left and right hemispheres
          are shown on the left and right sides of the figure.
      %(output_file)s
      %(title)s
      %(colorbar)s
  
          .. note::
              This function uses a symmetric colorbar for the statistical map.
  
          Default=True.
      %(vmin)s
      %(vmax)s
      %(threshold)s
      %(symmetric_cbar)s
      %(cmap)s
          Default='cold_hot'.
      %(cbar_tick_format)s
      kwargs : dict, optional
          keyword arguments passed to plot_surf_stat_map.
  
      See Also
      --------
      nilearn.datasets.fetch_surf_fsaverage : For surface data object to be
          used as the default background map for this plotting function.
  
      nilearn.surface.vol_to_surf : For info on the generation of surfaces.
  
      nilearn.plotting.plot_surf_stat_map : For info on kwargs options
          accepted by plot_img_on_surf.
  
      """
      for arg in ("figure", "axes", "engine"):
          if arg in kwargs:
              raise ValueError(
                  "plot_img_on_surf does not accept "
                  f"{arg} as an argument"
              )
  
      stat_map = check_niimg_3d(stat_map, dtype="auto")
      modes = _check_views(views)
      hemis = _check_hemispheres(hemispheres)
      surf_mesh = check_mesh(surf_mesh)
  
      mesh_prefix = "infl" if inflate else "pial"
      surf = {
          "left": surf_mesh[f"{mesh_prefix}_left"],
          "right": surf_mesh[f"{mesh_prefix}_right"],
      }
  
      texture = {
          "left": vol_to_surf(
              stat_map, surf_mesh["pial_left"], mask_img=mask_img
          ),
          "right": vol_to_surf(
              stat_map, surf_mesh["pial_right"], mask_img=mask_img
          ),
      }
  
      cbar_h = 0.25
      title_h = 0.25 * (title is not None)
      w, h = plt.figaspect(
          (len(modes) + cbar_h + title_h) / len(hemispheres)
      )
      fig = plt.figure(figsize=(w, h), constrained_layout=False)
      height_ratios = [title_h] + [1.0] * len(modes) + [cbar_h]
      grid = gridspec.GridSpec(
          len(modes) + 2,
          len(hemis),
          left=0.0,
          right=1.0,
          bottom=0.0,
          top=1.0,
          height_ratios=height_ratios,
          hspace=0.0,
          wspace=0.0,
      )
      axes = []
  
      # get vmin and vmax for entire data (all hemis)
      _, _, vmin, vmax = get_colorbar_and_data_ranges(
          image.get_data(stat_map),
          vmin=vmin,
          vmax=vmax,
          symmetric_cbar=symmetric_cbar,
      )
  
      for i, (mode, hemi) in enumerate(itertools.product(modes, hemis)):
          bg_map = None
          # By default, add curv sign background map if mesh is inflated,
          # sulc depth background map otherwise
          if inflate:
              curv_map = surface.load_surf_data(
                  surf_mesh[f"curv_{hemi}"]
              )
              curv_sign_map = (np.sign(curv_map) + 1) / 4 + 0.25
              bg_map = curv_sign_map
          else:
              sulc_map = surf_mesh[f"sulc_{hemi}"]
              bg_map = sulc_map
  
          ax = fig.add_subplot(grid[i + len(hemis)], projection="3d")
          axes.append(ax)
  
          plot_surf_stat_map(
              surf[hemi],
              texture[hemi],
              view=mode,
              hemi=hemi,
              bg_map=bg_map,
              bg_on_data=bg_on_data,
              axes=ax,
              colorbar=False,  # Colorbar created externally.
              vmin=vmin,
              vmax=vmax,
              threshold=threshold,
              cmap=cmap,
              symmetric_cbar=symmetric_cbar,
              **kwargs,
          )
  
          # We increase this value to better position the camera of the
          # 3D projection plot. The default value makes meshes look too small.
          ax.set_box_aspect(None, zoom=1.3)
  
      if colorbar:
          sm = _colorbar_from_array(
              image.get_data(stat_map),
              vmin,
              vmax,
              threshold,
              symmetric_cbar=symmetric_cbar,
              cmap=plt.get_cmap(cmap),
          )
  
          cbar_grid = gridspec.GridSpecFromSubplotSpec(
              3, 3, grid[-1, :]
          )
          cbar_ax = fig.add_subplot(cbar_grid[1])
          axes.append(cbar_ax)
          # Get custom ticks to set in colorbar
          ticks = _get_ticks_matplotlib(
              vmin, vmax, cbar_tick_format, threshold
          )
          fig.colorbar(
              sm,
              cax=cbar_ax,
              orientation="horizontal",
              ticks=ticks,
              format=cbar_tick_format,
          )
  
      if title is not None:
          fig.suptitle(
              title, y=1.0 - title_h / sum(height_ratios), va="bottom"
          )
  
      if output_file is not None:
          fig.savefig(output_file, bbox_inches="tight")
          plt.close(fig)
      else:
          return fig, axes
  
imports: import itertools
  import math
  from collections.abc import Sequence
  from warnings import warn
  import matplotlib
  import matplotlib.pyplot
  import numpy
  from matplotlib import gridspec
  from matplotlib.cm import ScalarMappable
  from matplotlib.colorbar import make_axes
  from matplotlib.colors import LinearSegmentedColormap, Normalize, to_rgba
  from matplotlib.patches import Patch
  from mpl_toolkits.mplot3d.art3d import Poly3DCollection
  from nilearn import image, surface
  from nilearn._utils import check_niimg_3d, compare_version, fill_doc
  from nilearn._utils.helpers import is_kaleido_installed, is_plotly_installed
  from nilearn.plotting.cm import cold_hot, mix_colormaps
  from nilearn.plotting.displays._slicers import _get_cbar_ticks
  from nilearn.plotting.html_surface import get_vertexcolor
  from nilearn.plotting.img_plotting import get_colorbar_and_data_ranges
  from nilearn.plotting.js_plotting_utils import colorscale
  from nilearn.surface import load_surf_data, load_surf_mesh, vol_to_surf
  from nilearn.surface.surface import check_mesh
label_desc: Use image node_id 27 for calling a global function with example usage: plot_img_on_surf(stat_map, surf_mesh, mask_img, hemispheres, bg_on_data, inflate, views, output_file, title, colorbar, vmin, vmax, threshold, symmetric_cbar, cmap, cbar_tick_format) and returns: fig,  axes