code: def plot_residuals(
      residuals: Union[np.ndarray, pd.Series] = None,
      y_true: Union[np.ndarray, pd.Series] = None,
      y_pred: Union[np.ndarray, pd.Series] = None,
      fig: matplotlib.figure.Figure = None,
      **fig_kw,
  ) -> matplotlib.figure.Figure:
      """
      Parameters
      ----------
      residuals : pandas Series, numpy ndarray, default `None`.
          Values of residuals. If `None`, residuals are calculated internally using
          `y_true` and `y_true`.
      y_true : pandas Series, numpy ndarray, default `None`.
          Ground truth (correct) values. Ignored if residuals is not `None`.
      y_pred : pandas Series, numpy ndarray, default `None`.
          Values of predictions. Ignored if residuals is not `None`.
      fig : matplotlib.figure.Figure, default `None`.
          Pre-existing fig for the plot. Otherwise, call matplotlib.pyplot.figure()
          internally.
      fig_kw : dict
          Other keyword arguments are passed to matplotlib.pyplot.figure()
  
      Returns
      -------
      fig: matplotlib.figure.Figure
          Matplotlib Figure.
  
      """
  
      if residuals is None and (y_true is None or y_pred is None):
          raise ValueError(
              "If `residuals` argument is None then, `y_true` and `y_pred` must be provided."
          )
  
      if residuals is None:
          residuals = y_pred - y_true
  
      if fig is None:
          fig = plt.figure(constrained_layout=True, **fig_kw)
  
      gs = matplotlib.gridspec.GridSpec(2, 2, figure=fig)
      ax1 = plt.subplot(gs[0, :])
      ax2 = plt.subplot(gs[1, 0])
      ax3 = plt.subplot(gs[1, 1])
  
      ax1.plot(residuals)
      sns.histplot(residuals, kde=True, bins=30, ax=ax2)
      plot_acf(residuals, ax=ax3, lags=60)
  
      ax1.set_title("Residuals")
      ax2.set_title("Distribution")
      ax3.set_title("Autocorrelation")
  
      return fig
  
file_path: skforecast/skforecast/plot/plot.py
imports: from typing import Union, Any, Optional
  import numpy
  import pandas
  from ..utils import check_optional_dependency
label_desc: Use image node_id 1 for calling a global function with example usage: plot_residuals(residuals, y_true, y_pred, fig) and returns: fig