code: def _plot_differences(
      model: Model,
      conditional_info: ConditionalInfo,
      summary_df: pd.DataFrame,
      average_by: Union[str, list, None] = None,
      transforms=None,
      legend: bool = True,
      ax=None,
      fig_kwargs=None,
      subplot_kwargs=None,
  ):
      """
      Common function used for both 'plot_comparisons' and 'plot_slopes'.
      """
      if (subplot_kwargs and not average_by) or (
          subplot_kwargs and average_by
      ):
          for key, value in subplot_kwargs.items():
              conditional_info.covariates.update({key: value})
          covariates = get_covariates(conditional_info.covariates)
      elif average_by and not subplot_kwargs:
          if not isinstance(average_by, list):
              average_by = listify(average_by)
          covariate_kinds = ("main", "group", "panel")
          average_by = dict(zip(covariate_kinds, average_by))
          covariates = get_covariates(average_by)
      else:
          covariates = get_covariates(conditional_info.covariates)
  
      if transforms is None:
          transforms = {}
  
      response_name = get_aliased_name(
          model.response_component.response_term
      )
  
      if ax is None:
          fig_kwargs = {} if fig_kwargs is None else fig_kwargs
          panels_n = (
              len(np.unique(summary_df[covariates.panel]))
              if covariates.panel
              else 1
          )
          rows, cols = default_grid(panels_n)
          fig, axes = create_axes_grid(
              panels_n, rows, cols, backend_kwargs=fig_kwargs
          )
          axes = np.atleast_1d(axes)
      else:
          axes = np.atleast_1d(ax)
          if isinstance(axes[0], np.ndarray):
              fig = axes[0][0].get_figure()
          else:
              fig = axes[0].get_figure()
  
      if is_numeric_dtype(summary_df[covariates.main]):
          # main condition variable can be numeric but at the same time only
          # a few values, so it is treated as categoric
          if np.unique(summary_df[covariates.main]).shape[0] <= 5:
              axes = plot_categoric(
                  covariates, summary_df, legend, axes
              )
          else:
              axes = plot_numeric(
                  covariates, summary_df, transforms, legend, axes
              )
      elif is_categorical_dtype(
          summary_df[covariates.main]
      ) or is_string_dtype(summary_df[covariates.main]):
          axes = plot_categoric(covariates, summary_df, legend, axes)
      else:
          raise TypeError(
              "Main covariate must be numeric or categoric."
          )
  
      response_name = get_aliased_name(
          model.response_component.response_term
      )
      for (
          ax
      ) in (
          axes.ravel()
      ):  # pylint: disable = redefined-argument-from-local
          ax.set(xlabel=covariates.main, ylabel=response_name)
  
      return fig, axes
  
file_path: bambi/bambi/interpret/plotting.py
imports: from typing import Union
  import arviz
  from arviz.plots.backends.matplotlib import create_axes_grid
  from arviz.plots.plot_utils import default_grid
  import numpy
  import pandas
  from pandas.api.types import is_categorical_dtype, is_numeric_dtype, is_string_dtype
  from bambi.models import Model
  from bambi.interpret.effects import comparisons, slopes, predictions
  from bambi.interpret.plot_types import plot_categoric, plot_numeric
  from bambi.interpret.utils import get_covariates, ConditionalInfo
  from bambi.utils import get_aliased_name, listify
label_desc: Use image node_id 1 for calling a global function with example usage: _plot_differences(model, conditional_info, summary_df, average_by, transforms, legend, ax, fig_kwargs, subplot_kwargs) and returns: fig,  axes