docs: def save_diagnostic_plots(
      outname,
      sampler,
      modelidxs=None,
      pdf=False,
      sed=True,
      blob_labels=None,
      last_step=False,
      dpi=100,
  ):
      """
      Generate diagnostic plots.
  
      - A plot for each of the chain parameters showing walker progression, final
        sample distribution and several statistical measures of this
        distribution: ``outname_chain_parN.png`` (see `naima.plot_chain`).
      - A corner plot of sample density in the two dimensional parameter space of
        all parameter pairs of the run, with the Maximum Likelihood parameter
        vector indicated in blue: ``outname_corner.png`` (see `corner.corner`).
      - A plot for each of the models returned as blobs by the model function.
        The maximum likelihood model is shown, as well as the 1 and 3 sigma
        confidence level contours. The first model will be compared with
        observational data and residuals shown. ``outname_fit_modelN.png`` (see
        `naima.plot_fit` and `naima.plot_blob`).
  
      Parameters
      ----------
      outname : str
          Name to be used to save diagnostic plot files.
  
      sampler : `emcee.EnsembleSampler` instance
          Sampler instance from which chains, blobs and data are read.
  
      modelidxs : iterable of integers, optional
          Model numbers to be plotted. Default: All returned in sampler.blobs
  
      blob_labels : list of strings, optional
          Label for each of the outputs of the model. They will be used as title
          for the corresponding plot.
  
      pdf : bool, optional
          Whether to save plots to multipage pdf.
      """
  
      from .plot import plot_chain, plot_blob, plot_corner
      from matplotlib import pyplot as plt
  
      # This function should never be interactive
      old_interactive = plt.rcParams["interactive"]
      plt.rcParams["interactive"] = False
  
      if pdf:
          plt.rc("pdf", fonttype=42)
          log.info(
              "Saving diagnostic plots in file " "{0}_plots.pdf".format(outname)
          )
          from matplotlib.backends.backend_pdf import PdfPages
  
          outpdf = PdfPages("{0}_plots.pdf".format(outname))
  
      # Chains
  
      for par, label in six.moves.zip(
          six.moves.range(sampler.chain.shape[-1]), sampler.labels
      ):
          try:
              log.info("Plotting chain of parameter {0}...".format(label))
              f = plot_chain(sampler, par, last_step=last_step)
              if pdf:
                  f.savefig(outpdf, format="pdf", dpi=dpi)
              else:
                  if "log(" in label or "log10(" in label:
                      label = label.split("(")[-1].split(")")[0]
                  f.savefig("{0}_chain_{1}.png".format(outname, label), dpi=dpi)
              f.clf()
              plt.close(f)
          except Exception as e:
              log.warning(
                  "plot_chain failed for paramter"
                  " {0} ({1}): {2}".format(label, par, e)
              )
  
      # Corner plot
  
      log.info("Plotting corner plot...")
  
      f = plot_corner(sampler)
      if f is not None:
          if pdf:
              f.savefig(outpdf, format="pdf", dpi=dpi)
          else:
              f.savefig("{0}_corner.png".format(outname), dpi=dpi)
          f.clf()
          plt.close(f)
  
      # Fit
  
      if modelidxs is None:
          nmodels = len(sampler.blobs[-1][0])
          modelidxs = list(six.moves.range(nmodels))
  
      if isinstance(sed, bool):
          sed = [sed for idx in modelidxs]
  
      if blob_labels is None:
          blob_labels = ["Model output {0}".format(idx) for idx in modelidxs]
      elif len(modelidxs) == 1 and isinstance(blob_labels, str):
          blob_labels = [blob_labels]
      elif len(blob_labels) < len(modelidxs):
          # Add labels
          n = len(blob_labels)
          blob_labels += [
              "Model output {0}".format(idx) for idx in modelidxs[n:]
          ]
  
      for modelidx, plot_sed, label in six.moves.zip(
          modelidxs, sed, blob_labels
      ):
  
          try:
              log.info("Plotting {0}...".format(label))
              f = plot_blob(
                  sampler,
                  blobidx=modelidx,
                  label=label,
                  sed=plot_sed,
                  n_samples=100,
                  last_step=last_step,
              )
              if pdf:
                  f.savefig(outpdf, format="pdf", dpi=dpi)
              else:
                  f.savefig(
                      "{0}_model{1}.png".format(outname, modelidx), dpi=dpi
                  )
              f.clf()
              plt.close(f)
          except Exception as e:
              log.warning("plot_blob failed for {0}: {1}".format(label, e))
  
      if pdf:
          outpdf.close()
  
      # set interactive back to original
      plt.rcParams["interactive"] = old_interactive