code: def plot_time_series_differences(
      data: pd.DataFrame,
      fig_defaults: Dict[str, Any],
      data_label: Optional[str] = None,
      model_labels: Optional[List[str]] = None,
      hoverinfo: Optional[str] = "text",
      data_kwargs: Optional[Dict] = None,
      fig_kwargs: Optional[Dict] = None,
  ) -> PlotReturnType:
      """Plots the differenced data for the target time series (could be any data
      type of the data - original, imputed, transformed) or model residuals. If
      target series is provided, only one data type is supported at a time.
  
      Parameters
      ----------
      data : pd.DataFrame
          Data whose differenced data needs needs to be plotted.
      fig_defaults : Dict[str, Any]
          The default settings for the plotly plot. Must contain keys for "width",
          "height", and "template".
      data_label : Optional[str], optional
          If data is from the original target series, then the name of the target
          series, by default None.
      model_labels : Optional[List[str]], optional
          If data is from model residuals, then the name(s) of the model(s),
          by default None. At least one of data_label or model_labels must be provided.
      hoverinfo : Optional[str], optional
          Action when hovering over the plotly plot, by default "text"
      data_kwargs : Optional[Dict], optional
          The difference orders to use or lags to use for differencing, by default
          None which plots the original data with first differences. Only one of
          "order_list" or "lags_list" must be provided. e.g.
          "order_list" = [1, 2] will plot original, first and second differences.
          "lags_list" = [1, [1, 12] will plot original, first, and first difference
          with seasonal difference of 12.
          Additionally, user can also ask for diagnostic plots for the differences
          such as "acf", "pacf", "periodogram", "fft" by setting the value of these
          keys to True.
      fig_kwargs : Optional[Dict], optional
          Specific overrides by the user for the plotly figure settings,
          by default None. Can contain keys for "width", "height" and/or "template".
  
      Returns
      -------
      PlotReturnType
          The plotly figure object along with a dictionary with the plot data.
          The data can be returned to the user (if requested) so that the plot can
          be and customized by them if not supported by pycaret by default.
  
      Raises
      ------
      ValueError
          (1) When the data contains more than 1 column indicating more than 1 data type.
          (2) When both data_label and model_labels are None
      """
      if data.shape[1] != 1:
          raise ValueError(
              "plot_time_series_differences() only works on a single time series, "
              f"but {data.shape[1]} series were provided."
          )
  
      title = "Difference Plot"
      if model_labels is not None:
          title = f"{title} | Model Residuals"
          column_titles = [f"{model_labels[0]} Residuals"]
      elif data_label is not None:
          title = f"{title} | {data_label}"
          # Do not use data_label for column titles since the actual column name
          # has the more detailed data_type (e.g. with "transformed" at the end.)
          column_titles = [data.columns[0]]
      else:
          # Both model_labels and data_label are None
          raise ValueError(msg1)
  
      data_series = data.iloc[:, 0]
  
      fig, return_data_dict = None, None
  
      data_kwargs = data_kwargs or {}
      fig_kwargs = fig_kwargs or {}
  
      order_list = data_kwargs.get("order_list", None)
      lags_list = data_kwargs.get("lags_list", None)
  
      plot_acf = data_kwargs.get("acf", False)
      plot_pacf = data_kwargs.get("pacf", False)
      plot_periodogram = data_kwargs.get("periodogram", False)
      plot_fft = data_kwargs.get("fft", False)
  
      diff_list, name_list = get_diffs(
          data=data_series, order_list=order_list, lags_list=lags_list
      )
  
      if len(diff_list) == 0:
          # Issue with reconciliation of orders and diffs
          return fig, return_data_dict
  
      diff_list = [data_series] + diff_list
      name_list = [
          "Actual" if model_labels is None else "Residuals"
      ] + name_list
  
      rows = len(diff_list)
      cols = 1
      if plot_acf:
          cols = cols + 1
          column_titles.append("ACF")
      if plot_pacf:
          cols = cols + 1
          column_titles.append("PACF")
      if plot_periodogram:
          cols = cols + 1
          column_titles.append("Periodogram")
      if plot_fft:
          cols = cols + 1
          column_titles.append("FFT")
  
      fig = make_subplots(
          rows=rows,
          cols=cols,
          row_titles=name_list,
          column_titles=column_titles,
          shared_xaxes=True,
      )
  
      # Should the following be plotted - Time Series, ACF, PACF, Periodogram, FFT
      plots = [True, plot_acf, plot_pacf, plot_periodogram, plot_fft]
  
      # Which column should the plots be in
      plot_cols = np.cumsum(plots).tolist()
  
      for i, subplot_data in enumerate(diff_list):
          # Add difference data ----
  
          ts_to_plot = pd.DataFrame(subplot_data)
          ts_to_plot.columns = [name_list[i]]
          fig = time_series_subplot(
              fig=fig,
              data=ts_to_plot,
              row=i + 1,
              col=plot_cols[0],
              hoverinfo=hoverinfo,
          )
  
          # Add diagnostics if requested ----
          if plot_acf:
              fig, acf_data = corr_subplot(
                  fig=fig,
                  data=subplot_data,
                  row=i + 1,
                  col=plot_cols[1],
                  name=name_list[i],
                  plot="acf",
              )
  
          if plot_pacf:
              fig, pacf_data = corr_subplot(
                  fig=fig,
                  data=subplot_data,
                  row=i + 1,
                  col=plot_cols[2],
                  name=name_list[i],
                  plot="pacf",
              )
  
          if plot_periodogram:
              fig, periodogram_data = frequency_components_subplot(
                  fig=fig,
                  data=subplot_data,
                  row=i + 1,
                  col=plot_cols[3],
                  hoverinfo=hoverinfo,
                  name=name_list[i],
                  plot="periodogram",
              )
  
          if plot_fft:
              fig, fft_data = frequency_components_subplot(
                  fig=fig,
                  data=subplot_data,
                  row=i + 1,
                  col=plot_cols[4],
                  hoverinfo=hoverinfo,
                  name=name_list[i],
                  plot="fft",
              )
  
      fig = _plot_fig_update(fig, title, fig_defaults, fig_kwargs)
  
      return_data_dict = {
          "data": data_series,
          "diff_list": diff_list,
          "name_list": name_list,
      }
  
      if plot_acf:
          return_data_dict.update({"acf": acf_data})
      if plot_pacf:
          return_data_dict.update({"pacf": pacf_data})
      if plot_periodogram:
          return_data_dict.update({"periodogram": periodogram_data})
      if plot_fft:
          return_data_dict.update({"fft": fft_data})
  
      return fig, return_data_dict
  
file_path: pycaret/pycaret/internal/plots/time_series.py
imports: from typing import Any, Dict, List, Optional, Union
  import numpy
  import pandas
  import plotly.graph_objects
  from plotly.subplots import make_subplots
  from sktime.forecasting.model_selection import ExpandingWindowSplitter, SlidingWindowSplitter
  from pycaret.internal.plots.utils.time_series import PlotReturnType, _clean_model_results_labels, _get_subplot_rows_cols, _plot_fig_update, _resolve_hoverinfo, _update_fig_dimensions, corr_subplot, decomp_subplot, dist_subplot, frequency_components_subplot, plot_original_with_overlays, qq_subplot, time_series_subplot
  from pycaret.utils.generic import _resolve_dict_keys
  from pycaret.utils.time_series import get_diffs
label_desc: Use image node_id 9 for calling a global function with example usage: plot_time_series_differences(data, fig_defaults, data_label, model_labels, hoverinfo, data_kwargs, fig_kwargs) and returns: fig,  return_data_dict, fig,  return_data_dict