code: def _compute_surf_map_faces_matplotlib(
      surf_map, faces, avg_method, n_vertices, face_colors_size
  ):
      """Help for plot_surf.
  
      This function computes the surf map faces using the
      provided averaging method.
  
      .. note::
          This method is called exclusively when using matplotlib,
          since it only supports plotting face-colour maps and not
          vertex-colour maps.
  
      """
      surf_map_data = _check_surf_map(surf_map, n_vertices)
  
      # create face values from vertex values by selected avg methods
      error_message = (
          "avg_method should be either "
          "['mean', 'median', 'max', 'min'] "
          "or a custom function"
      )
      if isinstance(avg_method, str):
          try:
              avg_method = getattr(np, avg_method)
          except AttributeError:
              raise ValueError(error_message)
          surf_map_faces = avg_method(surf_map_data[faces], axis=1)
      elif callable(avg_method):
          surf_map_faces = np.apply_along_axis(
              avg_method, 1, surf_map_data[faces]
          )
  
          # check that surf_map_faces has the same length as face_colors
          if surf_map_faces.shape != (face_colors_size,):
              raise ValueError(
                  "Array computed with the custom function "
                  "from avg_method does not have the correct shape: "
                  f"{surf_map_faces[0]} != {face_colors_size}"
              )
  
          # check that dtype is either int or float
          if not (
              "int" in str(surf_map_faces.dtype)
              or "float" in str(surf_map_faces.dtype)
          ):
              raise ValueError(
                  "Array computed with the custom function "
                  "from avg_method should be an array of numbers "
                  "(int or float)"
              )
      else:
          raise ValueError(error_message)
      return surf_map_faces
  
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 9 for calling a global function with example usage: _compute_surf_map_faces_matplotlib(surf_map, faces, avg_method, n_vertices, face_colors_size) and returns: surf_map_faces