code: def plot_map_3d(
      map,
      affine,
      cut_coords=None,
      anat=None,
      anat_affine=None,
      threshold=None,
      offscreen=False,
      vmin=None,
      vmax=None,
      cmap=None,
      view=(38.5, 70.5, 300, (-2.7, -12, 9.1)),
  ):
      """Plot a 3D volume rendering view of the activation, with an
      outline of the brain.
  
      Parameters
      ----------
      map : 3D ndarray
          The activation map, as a 3D image.
      affine : 4x4 ndarray
          The affine matrix going from image voxel space to MNI space.
      cut_coords: 3-tuple of floats, optional
          The MNI coordinates of a 3D cursor to indicate a feature
          or a cut, in MNI coordinates and order.
      anat : 3D ndarray, optional
          The anatomical image to be used as a background. If None, the
          MNI152 T1 1mm template is used. If False, no anatomical
          image is used.
      anat_affine : 4x4 ndarray, optional
          The affine matrix going from the anatomical image voxel space to
          MNI space. This parameter is not used when the default
          anatomical is used, but it is compulsory when using an
          explicit anatomical image.
      threshold : float, optional
          The lower threshold of the positive activation. This
          parameter is used to threshold the activation map.
      offscreen: boolean, optional
          If True, Mayavi attempts to plot offscreen. Will work only
          with VTK >= 5.2.
      vmin : float, optional
          The minimal value, for the colormap
      vmax : float, optional
          The maximum value, for the colormap
      cmap : a callable, or a pyplot colormap
          A callable returning a (n, 4) array for n values between
          0 and 1 for the colors. This can be for instance a pyplot
          colormap.
  
      Notes
      -----
  
      If you are using a VTK version below 5.2, there is no way to
      avoid opening a window during the rendering under Linux. This is
      necessary to use the graphics card for the rendering. You must
      maintain this window on top of others and on the screen.
  
      """
      # Late import to avoid triggering wx imports before needed.
      try:
          from mayavi import mlab
      except ImportError:
          # Try out old install of Mayavi, with namespace packages
          from enthought.mayavi import mlab
      if offscreen:
          global off_screen_engine
          if off_screen_engine is None:
              try:
                  from mayavi.core.off_screen_engine import (
                      OffScreenEngine,
                  )
              except ImportError:
                  # Try out old install of Mayavi, with namespace packages
                  from enthought.mayavi.core.off_screen_engine import (
                      OffScreenEngine,
                  )
              off_screen_engine = OffScreenEngine()
          off_screen_engine.start()
          fig = mlab.figure(
              "__private_plot_map_3d__",
              bgcolor=(1, 1, 1),
              fgcolor=(0, 0, 0),
              size=(400, 330),
              engine=off_screen_engine,
          )
          mlab.clf(figure=fig)
      else:
          fig = mlab.gcf()
          fig = mlab.figure(
              fig, bgcolor=(1, 1, 1), fgcolor=(0, 0, 0), size=(400, 350)
          )
      disable_render = fig.scene.disable_render
      fig.scene.disable_render = True
      if threshold is None:
          threshold = stats.scoreatpercentile(np.abs(map).ravel(), 80)
      contours = []
      lower_map = map[map <= -threshold]
      if np.any(lower_map):
          contours.append(lower_map.max())
      upper_map = map[map >= threshold]
      if np.any(upper_map):
          contours.append(map[map > threshold].min())
  
      ###########################################################################
      # Display the map using iso-surfaces
      if len(contours) > 0:
          map_src = affine_img_src(map, affine)
          module = mlab.pipeline.iso_surface(
              map_src, contours=contours, vmin=vmin, vmax=vmax
          )
          if hasattr(cmap, "__call__"):
              # Stick the colormap in mayavi
              module.module_manager.scalar_lut_manager.lut.table = (
                  255 * cmap(np.linspace(0, 1, 256))
              ).astype(np.int_)
      else:
          module = None
  
      if not anat is False:
          plot_anat_3d(
              anat=anat,
              anat_affine=anat_affine,
              scale=1.05,
              outline_color=(0.9, 0.9, 0.9),
              gyri_opacity=0.2,
          )
  
      ###########################################################################
      # Draw the cursor
      if cut_coords is not None:
          x0, y0, z0 = cut_coords
          mlab.plot3d(
              (-90, 90),
              (y0, y0),
              (z0, z0),
              color=(0.5, 0.5, 0.5),
              tube_radius=0.25,
          )
          mlab.plot3d(
              (x0, x0),
              (-126, 91),
              (z0, z0),
              color=(0.5, 0.5, 0.5),
              tube_radius=0.25,
          )
          mlab.plot3d(
              (x0, x0),
              (y0, y0),
              (-72, 109),
              color=(0.5, 0.5, 0.5),
              tube_radius=0.25,
          )
  
      mlab.view(*view)
      fig.scene.disable_render = disable_render
  
      return module
  
file_path: nipy/nipy/labs/viz_tools/maps_3d.py
imports: import os
  import tempfile
  import numpy
  from scipy import stats
  from .anat_cache import _AnatCache, mni_sform, mni_sform_inv
  from .coord_tools import coord_transform
label_desc: Use image node_id 5 for calling a global function with example usage: plot_map_3d(map, affine, cut_coords, anat, anat_affine, threshold, offscreen, vmin, vmax, cmap, view) and returns: module