code: def plot_gp_dist(
      ax,
      samples: np.ndarray,
      x: np.ndarray,
      plot_samples=True,
      palette="Reds",
      fill_alpha=0.8,
      samples_alpha=0.1,
      fill_kwargs=None,
      samples_kwargs=None,
  ):
      """A helper function for plotting 1D GP posteriors from trace
  
      Parameters
      ----------
      ax: axes
          Matplotlib axes.
      samples: numpy.ndarray
          Array of S posterior predictive sample from a GP.
          Expected shape: (S, X)
      x: numpy.ndarray
          Grid of X values corresponding to the samples.
          Expected shape: (X,) or (X, 1), or (1, X)
      plot_samples: bool
          Plot the GP samples along with posterior (defaults True).
      palette: str
          Palette for coloring output (defaults to "Reds").
      fill_alpha: float
          Alpha value for the posterior interval fill (defaults to 0.8).
      samples_alpha: float
          Alpha value for the sample lines (defaults to 0.1).
      fill_kwargs: dict
          Additional arguments for posterior interval fill (fill_between).
      samples_kwargs: dict
          Additional keyword arguments for samples plot.
  
      Returns
      -------
      ax: Matplotlib axes
      """
      import matplotlib.pyplot as plt
  
      if fill_kwargs is None:
          fill_kwargs = {}
      if samples_kwargs is None:
          samples_kwargs = {}
      if np.any(np.isnan(samples)):
          warnings.warn(
              "There are `nan` entries in the [samples] arguments. "
              "The plot will not contain a band!",
              UserWarning,
          )
  
      cmap = plt.get_cmap(palette)
      percs = np.linspace(51, 99, 40)
      colors = (percs - np.min(percs)) / (np.max(percs) - np.min(percs))
      samples = samples.T
      x = x.flatten()
      for i, p in enumerate(percs[::-1]):
          upper = np.percentile(samples, p, axis=1)
          lower = np.percentile(samples, 100 - p, axis=1)
          color_val = colors[i]
          ax.fill_between(
              x,
              upper,
              lower,
              color=cmap(color_val),
              alpha=fill_alpha,
              **fill_kwargs,
          )
      if plot_samples:
          # plot a few samples
          idx = np.random.randint(0, samples.shape[1], 30)
          ax.plot(
              x,
              samples[:, idx],
              color=cmap(0.9),
              lw=1,
              alpha=samples_alpha,
              **samples_kwargs,
          )
  
      return ax
  
file_path: pymc/pymc/gp/util.py
imports: import warnings
  import numpy
  import pytensor.tensor
  from pytensor.compile import SharedVariable
  from pytensor.graph import ancestors
  from pytensor.tensor.variable import TensorConstant
  from scipy.cluster.vq import kmeans
  from pymc.distributions.distribution import Distribution
  from pymc.model import modelcontext
  from pymc.pytensorf import compile_pymc
label_desc: Use image node_id 5 for calling a global function with example usage: plot_gp_dist(ax, samples, x, plot_samples, palette, fill_alpha, samples_alpha, fill_kwargs, samples_kwargs) and returns: ax