code: def plot_event(
      model_event, cmap=None, output_file=None, **fig_kwargs
  ):
      """Create plot for event visualization.
  
      Parameters
      ----------
      model_event : :class:`pandas.DataFrame` or :obj:`list`\
      of :class:`pandas.DataFrame`
          The :class:`pandas.DataFrame` must have three columns:
          ``trial_type`` with event name, ``onset`` and ``duration``.
  
          .. note::
  
              The :class:`pandas.DataFrame` can also be obtained
              from :func:`nilearn.glm.first_level.first_level_from_bids`.
  
      %(cmap)s
      %(output_file)s
      **fig_kwargs : extra keyword arguments, optional
          Extra arguments passed to :func:`matplotlib.pyplot.subplots`.
  
      Returns
      -------
      figure : :class:`matplotlib.figure.Figure`
          Plot Figure object.
  
      """
      if isinstance(model_event, pd.DataFrame):
          model_event = [model_event]
  
      for i, event in enumerate(model_event):
          event_copy = check_events(event)
          model_event[i] = event_copy
  
      n_runs = len(model_event)
      figure, ax = plt.subplots(1, 1, **fig_kwargs)
  
      # input validation
      if cmap is None:
          cmap = plt.cm.tab20
      elif isinstance(cmap, str):
          cmap = plt.get_cmap(cmap)
  
      event_labels = pd.concat(
          event["trial_type"] for event in model_event
      )
      event_labels = np.unique(event_labels)
  
      cmap_dictionary = {
          label: idx for idx, label in enumerate(event_labels)
      }
  
      if len(event_labels) > cmap.N:
          plt.close()
          raise ValueError(
              "The number of event types is greater than "
              f" colors in colormap ({len(event_labels)} > {cmap.N}). "
              "Use a different colormap."
          )
  
      for idx_run, event_df in enumerate(model_event):
          for _, event in event_df.iterrows():
              ymin = (idx_run + 0.25) / n_runs
              ymax = (idx_run + 0.75) / n_runs
              event_onset = event["onset"]
              event_end = event["onset"] + event["duration"]
              color = cmap.colors[cmap_dictionary[event["trial_type"]]]
  
              if event["duration"] != 0:
                  ax.axvspan(
                      event_onset,
                      event_end,
                      ymin=ymin,
                      ymax=ymax,
                      facecolor=color,
                  )
  
              # events will 0 duration are plotted as lines
              else:
                  ax.axvline(
                      event_onset,
                      ymin=ymin,
                      ymax=ymax,
                      color=color,
                  )
  
      handles = []
      for label, idx in cmap_dictionary.items():
          patch = mpatches.Patch(color=cmap.colors[idx], label=label)
          handles.append(patch)
  
      _ = ax.legend(handles=handles, ncol=4)
  
      ax.set_xlabel("Time (sec.)")
      ax.set_ylabel("Runs")
      ax.set_ylim(0, n_runs)
      ax.set_yticks(np.arange(n_runs) + 0.5)
      ax.set_yticklabels(np.arange(n_runs) + 1)
  
      plt.tight_layout()
      if output_file is not None:
          plt.savefig(output_file)
          plt.close()
          figure = None
  
      return figure
  
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 15 for calling a global function with example usage: plot_event(model_event, cmap, output_file) and returns: figure