code: def plot_confusion_matrix(
      confusion_matrix,
      labels,
      ids=None,
      samples=None,
      eval_key=None,
      gt_field=None,
      pred_field=None,
      backend="plotly",
      **kwargs,
  ):
      """Plots a confusion matrix.
  
      If ``ids`` are provided and you are working in a notebook environment with
      the default plotly backend, this method returns an interactive
      :class:`fiftyone.core.plots.plotly.InteractiveHeatmap` that you can attach
      to an App session via its :attr:`fiftyone.core.session.Session.plots`
      attribute, which will automatically sync the session's view with the
      currently selected cells in the confusion matrix.
  
      Args:
          confusion_matrix: a ``num_true x num_preds`` confusion matrix
          labels: a ``max(num_true, num_preds)`` array-like of class labels
          ids (None): an array-like of same shape as ``confusion_matrix``
              containing lists of IDs corresponding to each cell
          samples (None): the :class:`fiftyone.core.collections.SampleCollection`
              for which the confusion matrix was generated
          eval_key (None): the evaluation key of the evaluation
          gt_field (None): the name of the ground truth field
          pred_field (None): the name of the predictions field
          backend ("plotly"): the plotting backend to use. Supported values are
              ``("plotly", "matplotlib")``
          **kwargs: keyword arguments for the backend plotting method:
  
              -   "plotly" backend: :meth:`fiftyone.core.plots.plotly.plot_confusion_matrix`
              -   "matplotlib" backend: :meth:`fiftyone.core.plots.matplotlib.plot_confusion_matrix`
  
      Returns:
          one of the following
  
          -   a :class:`fiftyone.core.plots.plotly.InteractiveHeatmap`, if IDs
              are available and the plotly backend is used
          -   a :class:`fiftyone.core.plots.plotly.PlotlyNotebookPlot`, if no IDs
              are available but you are working in a Jupyter notebook with the
              plotly backend
          -   a plotly or matplotlib figure, otherwise
      """
      backend = _parse_backend(backend)
  
      if backend == "matplotlib":
          from .matplotlib import (
              plot_confusion_matrix as _plot_confusion_matrix,
          )
      else:
          from .plotly import (
              plot_confusion_matrix as _plot_confusion_matrix,
          )
  
          kwargs.update(
              dict(
                  ids=ids,
                  samples=samples,
                  eval_key=eval_key,
                  gt_field=gt_field,
                  pred_field=pred_field,
              )
          )
  
      return _plot_confusion_matrix(confusion_matrix, labels, **kwargs)
  
imports: import logging
  import fiftyone.core.context
  import fiftyone.core.labels
  import fiftyone.core.patches
  import fiftyone.core.video
label_desc: Use image node_id 1 for calling a global function with example usage: plot_confusion_matrix(confusion_matrix, labels, ids, samples, eval_key, gt_field, pred_field, backend) and returns: _plot_confusion_matrix