code: def plot_matrix(
      mat,
      title=None,
      labels=None,
      figure=None,
      axes=None,
      colorbar=True,
      cmap=plt.cm.RdBu_r,
      tri="full",
      auto_fit=True,
      grid=False,
      reorder=False,
      **kwargs,
  ):
      """Plot the given matrix.
  
      Parameters
      ----------
      mat : 2-D :class:`numpy.ndarray`
          Matrix to be plotted.
      %(title)s
      labels : :obj:`list`, or :class:`numpy.ndarray` of :obj:`str`,\
      or False, or None, optional
          The label of each row and column. Needs to be the same
          length as rows/columns of mat. If False, None, or an
          empty list, no labels are plotted.
  
      figure : :class:`matplotlib.figure.Figure`, figsize :obj:`tuple`,\
      or None, optional
          Sets the figure used. This argument can be either an existing
          figure, or a pair (width, height) that gives the size of a
          newly-created figure.
  
          .. note::
  
              Specifying both axes and figure is not allowed.
  
      axes : None or :class:`matplotlib.axes.Axes`, optional
          Axes instance to be plotted on. Creates a new one if None.
  
          .. note::
  
              Specifying both axes and figure is not allowed.
  
      %(colorbar)s
          Default=True.
      %(cmap)s
          Default=`plt.cm.RdBu_r`.
      tri : {'full', 'lower', 'diag'}, default='full'
          Which triangular part of the matrix to plot:
  
              - 'lower': Plot the lower part
              - 'diag': Plot the lower part with the diagonal
              - 'full': Plot the full matrix
  
  
      auto_fit : :obj:`bool`, default=True
          If auto_fit is True, the axes are dimensioned to give room
          for the labels. This assumes that the labels are resting
          against the bottom and left edges of the figure.
  
      grid : color or False, default=False
          If not False, a grid is plotted to separate rows and columns
          using the given color.
  
      reorder : :obj:`bool` or {'single', 'complete', 'average'}, default=False
          If not False, reorders the matrix into blocks of clusters.
          Accepted linkage options for the clustering are 'single',
          'complete', and 'average'. True defaults to average linkage.
  
          .. note::
              This option is only available with SciPy >= 1.0.0.
  
          .. versionadded:: 0.4.1
  
      kwargs : extra keyword arguments, optional
          Extra keyword arguments are sent to pylab.imshow.
  
      Returns
      -------
      display : :class:`matplotlib.axes.Axes`
          Axes image.
  
      """
      (
          labels,
          reorder,
          fig,
          axes,
          own_fig,
      ) = _sanitize_inputs_plot_matrix(
          mat.shape, tri, labels, reorder, figure, axes
      )
      if reorder:
          mat, labels = _reorder_matrix(mat, labels, reorder)
      if tri != "full":
          mat = _mask_matrix(mat, tri)
      display = axes.imshow(
          mat,
          aspect="equal",
          interpolation="nearest",
          cmap=cmap,
          **kwargs,
      )
      axes.set_autoscale_on(False)
      ymin, ymax = axes.get_ylim()
      _configure_axis(
          axes,
          labels,
          label_size="x-small",
          x_label_rotation=50,
          y_label_rotation=10,
      )
      if grid is not False:
          _configure_grid(axes, grid, tri, len(mat))
      axes.set_ylim(ymin, ymax)
      if auto_fit:
          if labels:
              _fit_axes(axes)
          elif own_fig:
              plt.tight_layout(
                  pad=0.1,
                  rect=((0, 0, 0.95, 1) if colorbar else (0, 0, 1, 1)),
              )
      if colorbar:
          divider = make_axes_locatable(axes)
          cax = divider.append_axes("right", size="5%", pad=0.0)
  
          plt.colorbar(display, cax=cax)
          fig.tight_layout()
  
      if title is not None:
          axes.set_title(title, size=16)
          fig.tight_layout()
  
      return display
  
imports: import warnings
  import matplotlib.patches
  import matplotlib.pyplot
  import numpy
  import pandas
  from mpl_toolkits.axes_grid1 import make_axes_locatable
  from scipy.cluster.hierarchy import leaves_list, linkage, optimal_leaf_ordering
  from nilearn.glm.first_level.experimental_paradigm import check_events
  from .._utils import fill_doc
label_desc: Use image node_id 11 for calling a global function with example usage: plot_matrix(mat, title, labels, figure, axes, colorbar, cmap, tri, auto_fit, grid, reorder) and returns: display