code: def plot_forest(
      ax,
      datasets,
      var_names,
      model_names,
      combined,
      combine_dims,
      colors,
      figsize,
      width_ratios,
      linewidth,
      markersize,
      kind,
      ncols,
      hdi_prob,
      quartiles,
      rope,
      ridgeplot_overlap,
      ridgeplot_alpha,
      ridgeplot_kind,
      ridgeplot_truncate,
      ridgeplot_quantiles,
      textsize,
      legend,
      labeller,
      ess,
      r_hat,
      backend_kwargs,
      backend_config,  # pylint: disable=unused-argument
      show,
  ):
      """Matplotlib forest plot."""
      plot_handler = PlotHandler(
          datasets,
          var_names=var_names,
          model_names=model_names,
          combined=combined,
          combine_dims=combine_dims,
          colors=colors,
          labeller=labeller,
      )
  
      if figsize is None:
          if kind == "ridgeplot":
              figsize = (
                  min(14, sum(width_ratios) * 4),
                  plot_handler.fig_height() * 1.2,
              )
          else:
              figsize = (
                  min(12, sum(width_ratios) * 2),
                  plot_handler.fig_height(),
              )
  
      (
          figsize,
          _,
          titlesize,
          xt_labelsize,
          auto_linewidth,
          auto_markersize,
      ) = _scale_fig_size(figsize, textsize, 1.1, 1)
  
      if linewidth is None:
          linewidth = auto_linewidth
  
      if markersize is None:
          markersize = auto_markersize
  
      if backend_kwargs is None:
          backend_kwargs = {}
  
      backend_kwargs = {
          **backend_kwarg_defaults(),
          **backend_kwargs,
      }
  
      if ax is None:
          _, axes = plt.subplots(
              nrows=1,
              ncols=ncols,
              figsize=figsize,
              gridspec_kw={"width_ratios": width_ratios},
              sharey=True,
              **backend_kwargs,
          )
      else:
          axes = ax
  
      axes = np.atleast_1d(axes)
      if kind == "forestplot":
          plot_handler.forestplot(
              hdi_prob,
              quartiles,
              xt_labelsize,
              titlesize,
              linewidth,
              markersize,
              axes[0],
              rope,
          )
      elif kind == "ridgeplot":
          plot_handler.ridgeplot(
              hdi_prob,
              ridgeplot_overlap,
              linewidth,
              markersize,
              ridgeplot_alpha,
              ridgeplot_kind,
              ridgeplot_truncate,
              ridgeplot_quantiles,
              axes[0],
          )
      else:
          raise TypeError(
              f"Argument 'kind' must be one of 'forestplot' "
              f"or 'ridgeplot' (you provided {kind})"
          )
  
      idx = 1
      if ess:
          plot_handler.plot_neff(
              axes[idx], xt_labelsize, titlesize, markersize
          )
          idx += 1
  
      if r_hat:
          plot_handler.plot_rhat(
              axes[idx], xt_labelsize, titlesize, markersize
          )
          idx += 1
  
      for ax_ in axes:
          if kind == "ridgeplot":
              ax_.grid(False)
          else:
              ax_.grid(False, axis="y")
          # Remove ticklines on y-axes
          ax_.tick_params(axis="y", left=False, right=False)
  
          for loc, spine in ax_.spines.items():
              if loc in ["left", "right"]:
                  spine.set_visible(False)
  
          if len(plot_handler.data) > 1:
              plot_handler.make_bands(ax_)
  
      labels, ticks = plot_handler.labels_and_ticks()
      axes[0].set_yticks(ticks)
      axes[0].set_yticklabels(labels)
      all_plotters = list(plot_handler.plotters.values())
      y_max = plot_handler.y_max() - all_plotters[-1].group_offset
      if kind == "ridgeplot":  # space at the top
          y_max += ridgeplot_overlap
      axes[0].set_ylim(-all_plotters[0].group_offset, y_max)
      if legend:
          plot_handler.legend(ax=axes[0])
  
      if backend_show(show):
          plt.show()
  
      return axes
  
imports: from collections import OrderedDict, defaultdict
  from itertools import tee
  import matplotlib.pyplot
  import numpy
  from matplotlib.colors import to_rgba
  from matplotlib.lines import Line2D
  from ....stats import hdi
  from ....stats.density_utils import get_bins, histogram, kde
  from ....stats.diagnostics import _ess, _rhat
  from ....sel_utils import xarray_var_iter
  from ....utils import conditional_jit
  from ...plot_utils import _scale_fig_size
  from .None import backend_kwarg_defaults, backend_show
label_desc: Use image node_id 2 for calling a global function with example usage: plot_forest(ax, datasets, var_names, model_names, combined, combine_dims, colors, figsize, width_ratios, linewidth, markersize, kind, ncols, hdi_prob, quartiles, rope, ridgeplot_overlap, ridgeplot_alpha, ridgeplot_kind, ridgeplot_truncate, ridgeplot_quantiles, textsize, legend, labeller, ess, r_hat, backend_kwargs, backend_config, show) and returns: axes