code: def plot_contrast_matrix(
      contrast_def,
      design_matrix,
      colorbar=False,
      ax=None,
      output_file=None,
  ):
      """Create plot for :term:`contrast` definition.
  
      Parameters
      ----------
      contrast_def : :obj:`str` or :class:`numpy.ndarray` of shape[1] <= n_col \
          where ``n_col`` is the number of columns of the design matrix.
          The string can be a formula compatible
          with :meth:`pandas.DataFrame.eval`.
          Basically one can use the name of the conditions
          as they appear in the design matrix of the fitted model
          combined with operators +-
          and combined with numbers with operators +-`*`/.
      design_matrix : :class:`pandas.DataFrame`
          Design matrix to use.
      %(colorbar)s
          Default=False.
      ax : :class:`matplotlib.axes.Axes`, optional
          Axis on which to plot the figure.
          If None, a new figure will be created.
      %(output_file)s
  
      Returns
      -------
      ax : :class:`matplotlib.axes.Axes`
          Figure object.
  
      """
      contrast_def = pad_contrast_matrix(contrast_def, design_matrix)
      con_matrix = np.asmatrix(contrast_def)
  
      design_column_names = design_matrix.columns.tolist()
      max_len = np.max([len(str(name)) for name in design_column_names])
  
      nb_columns_design_matrix = len(design_column_names)
      if ax is None:
          plt.figure(
              figsize=(
                  0.4 * nb_columns_design_matrix,
                  1 + 0.5 * con_matrix.shape[0] + 0.04 * max_len,
              )
          )
          ax = plt.gca()
  
      maxval = np.max(np.abs(contrast_def))
      mat = ax.matshow(
          con_matrix,
          aspect="equal",
          cmap="gray",
          vmin=-maxval,
          vmax=maxval,
      )
  
      ax.set_label("conditions")
      ax.set_ylabel("")
      ax.set_yticks(())
  
      ax.xaxis.set(ticks=np.arange(nb_columns_design_matrix))
      ax.set_xticklabels(design_column_names, rotation=50, ha="left")
  
      if colorbar:
          plt.colorbar(mat, fraction=0.025, pad=0.04)
  
      plt.tight_layout()
      plt.subplots_adjust(
          top=np.min([0.3 + 0.05 * con_matrix.shape[0], 0.55])
      )
  
      if output_file is not None:
          plt.savefig(output_file)
          plt.close()
          ax = None
  
      return ax
  
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 12 for calling a global function with example usage: plot_contrast_matrix(contrast_def, design_matrix, colorbar, ax, output_file) and returns: ax