code: def _plot_surf_plotly(
      coords,
      faces,
      surf_map=None,
      bg_map=None,
      hemi="left",
      view="lateral",
      cmap=None,
      symmetric_cmap=True,
      colorbar=False,
      threshold=None,
      bg_on_data=False,
      darkness=0.7,
      vmin=None,
      vmax=None,
      cbar_vmin=None,
      cbar_vmax=None,
      cbar_tick_format=".1f",
      title=None,
      title_font_size=18,
      output_file=None,
  ):
      """Help for plot_surf.
  
      .. versionadded:: 0.9.0
  
      This function handles surface plotting when the selected
      engine is plotly.
  
      .. note::
          This function assumes that plotly and kaleido are
          installed.
  
      .. warning::
          This function is new and experimental. Please report
          bugs that you may encounter.
  
      """
      if is_plotly_installed():
          import plotly.graph_objects as go
  
          from nilearn.plotting.displays import PlotlySurfaceFigure
      else:
          msg = "Using engine='plotly' requires that ``plotly`` is installed."
          raise ImportError(msg)
  
      x, y, z = coords.T
      i, j, k = faces.T
  
      if cmap is None:
          cmap = cold_hot
  
      bg_data = None
      if bg_map is not None:
          bg_data = load_surf_data(bg_map)
          if bg_data.shape[0] != coords.shape[0]:
              raise ValueError(
                  "The bg_map does not have the same number "
                  "of vertices as the mesh."
              )
  
      if surf_map is not None:
          _check_surf_map(surf_map, coords.shape[0])
          colors = colorscale(
              cmap,
              surf_map,
              threshold,
              vmax=vmax,
              vmin=vmin,
              symmetric_cmap=symmetric_cmap,
          )
          vertexcolor = get_vertexcolor(
              surf_map,
              colors["cmap"],
              colors["norm"],
              absolute_threshold=colors["abs_threshold"],
              bg_map=bg_data,
              bg_on_data=bg_on_data,
              darkness=darkness,
          )
      else:
          if bg_data is None:
              bg_data = np.zeros(coords.shape[0])
          colors = colorscale("Greys", bg_data, symmetric_cmap=False)
          vertexcolor = get_vertexcolor(
              bg_data,
              colors["cmap"],
              colors["norm"],
              absolute_threshold=colors["abs_threshold"],
          )
  
      mesh_3d = go.Mesh3d(
          x=x, y=y, z=z, i=i, j=j, k=k, vertexcolor=vertexcolor
      )
      fig_data = [mesh_3d]
      if colorbar:
          dummy = _get_cbar_plotly(
              colors["colors"],
              float(colors["vmin"]),
              float(colors["vmax"]),
              cbar_tick_format,
          )
          fig_data.append(dummy)
  
      # instantiate plotly figure
      camera_view = _get_view_plot_surf_plotly(hemi, view)
      fig = go.Figure(data=fig_data)
      fig.update_layout(
          scene_camera=camera_view,
          title=_configure_title_plotly(title, title_font_size),
          **LAYOUT,
      )
  
      # save figure
      plotly_figure = PlotlySurfaceFigure(
          figure=fig, output_file=output_file
      )
  
      if output_file is not None:
          if not is_kaleido_installed():
              msg = (
                  "Saving figures to file with engine='plotly' requires "
                  "that ``kaleido`` is installed."
              )
              raise ImportError(msg)
          plotly_figure.savefig()
  
      return plotly_figure
  
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 6 for calling a global function with example usage: _plot_surf_plotly(coords, faces, surf_map, bg_map, hemi, view, cmap, symmetric_cmap, colorbar, threshold, bg_on_data, darkness, vmin, vmax, cbar_vmin, cbar_vmax, cbar_tick_format, title, title_font_size, output_file) and returns: plotly_figure