code: def plot_map(
      map,
      affine,
      cut_coords=None,
      anat=None,
      anat_affine=None,
      slicer="ortho",
      figure=None,
      axes=None,
      title=None,
      threshold=None,
      annotate=True,
      draw_cross=True,
      do3d=False,
      threshold_3d=None,
      view_3d=(38.5, 70.5, 300, (-2.7, -12, 9.1)),
      black_bg=False,
      **imshow_kwargs,
  ):
      """Plot three cuts of a given activation map (Frontal, Axial, and Lateral)
  
      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: None, int, or a tuple of floats
          The MNI coordinates of the point where the cut is performed, in
          MNI coordinates and order.
          If slicer is 'ortho', this should be a 3-tuple: (x, y, z)
          For slicer == 'x', 'y', or 'z', then these are the
          coordinates of each cut in the corresponding direction.
          If None or an int is given, then a maximally separated sequence (
          with exactly cut_coords elements if cut_coords is not None) of
          cut coordinates along the slicer axis is computed automatically
      anat : 3D ndarray or False, optional
          The anatomical image to be used as a background. If None, the
          MNI152 T1 1mm template is used. If False, no anat is displayed.
      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.
      slicer: {'ortho', 'x', 'y', 'z'}
          Choose the direction of the cuts. With 'ortho' three cuts are
          performed in orthogonal directions
      figure : integer or matplotlib figure, optional
          Matplotlib figure used or its number. If None is given, a
          new figure is created.
      axes : matplotlib axes or 4 tuple of float: (xmin, ymin, width, height), optional
          The axes, or the coordinates, in matplotlib figure space,
          of the axes used to display the plot. If None, the complete
          figure is used.
      title : string, optional
          The title displayed on the figure.
      threshold : a number, None, or 'auto'
          If None is given, the maps are not thresholded.
          If a number is given, it is used to threshold the maps:
          values below the threshold are plotted as transparent. If
          auto is given, the threshold is determined magically by
          analysis of the map.
      annotate: boolean, optional
          If annotate is True, positions and left/right annotation
          are added to the plot.
      draw_cross: boolean, optional
          If draw_cross is True, a cross is drawn on the plot to
          indicate the cut plosition.
      do3d: {True, False or 'interactive'}, optional
          If True, Mayavi is used to plot a 3D view of the
          map in addition to the slicing. If 'interactive', the
          3D visualization is displayed in an additional interactive
          window.
      threshold_3d:
          The threshold to use for the 3D view (if any). Defaults to
          the same threshold as that used for the 2D view.
      view_3d: tuple,
          The view used to take the screenshot: azimuth, elevation,
          distance and focalpoint, see the docstring of mlab.view.
      black_bg: boolean, optional
          If True, the background of the image is set to be black. If
          you wish to save figures with a black background, you
          will need to pass "facecolor='k', edgecolor='k'" to pyplot's
          savefig.
      imshow_kwargs: extra keyword arguments, optional
          Extra keyword arguments passed to pyplot.imshow
  
      Notes
      -----
      Arrays should be passed in numpy convention: (x, y, z)
      ordered.
  
      Use masked arrays to create transparency:
  
          import numpy as np
          map = np.ma.masked_less(map, 0.5)
          plot_map(map, affine)
      """
  
      map, affine = _xyz_order(map, affine)
  
      nan_mask = np.isnan(np.asarray(map))
      if np.any(nan_mask):
          map = map.copy()
          map[nan_mask] = 0
      del nan_mask
  
      # Deal with automatic settings of plot parameters
      if threshold == "auto":
          # Threshold epsilon above a percentile value, to be sure that some
          # voxels are indeed threshold
          threshold = _fast_abs_percentile(map) + 1e-5
  
      if do3d:
          try:
              try:
                  from mayavi import version
              except ImportError:
                  from enthought.mayavi import version
              if not int(version.version[0]) > 2:
                  raise ImportError
          except ImportError:
              warnings.warn(
                  "Mayavi > 3.x not installed, plotting only 2D"
              )
              do3d = False
  
      if (
          cut_coords is None or isinstance(cut_coords, numbers.Number)
      ) and slicer in ["x", "y", "z"]:
          cut_coords = find_maxsep_cut_coords(
              map,
              affine,
              slicer=slicer,
              threshold=threshold,
              n_cuts=cut_coords,
          )
  
      slicer = SLICERS[slicer].init_with_figure(
          data=map,
          affine=affine,
          threshold=threshold,
          cut_coords=cut_coords,
          figure=figure,
          axes=axes,
          black_bg=black_bg,
          leave_space=do3d,
      )
  
      # Use Mayavi for the 3D plotting
      if do3d:
          from .maps_3d import m2screenshot, plot_map_3d
  
          try:
              from tvtk.api import tvtk
          except ImportError:
              from enthought.tvtk.api import tvtk
          version = tvtk.Version()
          offscreen = True
          if (version.vtk_major_version, version.vtk_minor_version) < (
              5,
              2,
          ):
              offscreen = False
          if do3d == "interactive":
              offscreen = False
  
          cmap = imshow_kwargs.get(
              "cmap", plt.get_cmap(plt.rcParams["image.cmap"])
          )
          # Computing vmin and vmax is costly in time, and is needed
          # later, so we compute them now, and store them for future
          # use
          vmin = imshow_kwargs.get("vmin", map.min())
          imshow_kwargs["vmin"] = vmin
          vmax = imshow_kwargs.get("vmax", map.max())
          imshow_kwargs["vmax"] = vmax
          try:
              from mayavi import mlab
          except ImportError:
              from enthought.mayavi import mlab
          if threshold_3d is None:
              threshold_3d = threshold
          plot_map_3d(
              np.asarray(map),
              affine,
              cut_coords=cut_coords,
              anat=anat,
              anat_affine=anat_affine,
              offscreen=offscreen,
              cmap=cmap,
              threshold=threshold_3d,
              view=view_3d,
              vmin=vmin,
              vmax=vmax,
          )
  
          ax = list(slicer.axes.values())[0].ax.figure.add_axes(
              (0.001, 0, 0.29, 1)
          )
          ax.axis("off")
          m2screenshot(mpl_axes=ax)
          if offscreen:
              # Clean up, so that the offscreen engine doesn't become the
              # default
              mlab.clf()
              engine = mlab.get_engine()
              try:
                  from mayavi.core.registry import registry
              except:
                  from enthought.mayavi.core.registry import registry
              for key, value in registry.engines.items():
                  if value is engine:
                      registry.engines.pop(key)
                      break
  
      if threshold:
          map = np.ma.masked_inside(
              map, -threshold, threshold, copy=False
          )
  
      _plot_anat(
          slicer,
          anat,
          anat_affine,
          title=title,
          annotate=annotate,
          draw_cross=draw_cross,
      )
  
      slicer.plot_map(map, affine, **imshow_kwargs)
      return slicer
  
file_path: nipy/nipy/labs/viz_tools/activation_maps.py
imports: import numbers
  import warnings
  import matplotlib.pyplot
  import numpy
  from nipy.utils import is_numlike
  from .anat_cache import _AnatCache, mni_sform, mni_sform_inv
  from .coord_tools import coord_transform, find_maxsep_cut_coords
  from .edge_detect import _fast_abs_percentile
  from .slicers import SLICERS, _xyz_order
label_desc: Use image node_id 1 for calling a global function with example usage: plot_map(map, affine, cut_coords, anat, anat_affine, slicer, figure, axes, title, threshold, annotate, draw_cross, do3d, threshold_3d, view_3d, black_bg) and returns: slicer