code: def generate_fig_individual_bin_comparison(
      data: Tuple, display_settings: dict
  ) -> None:
      """Generate figures to compare localization errors, error bounds accuracy, and Jaccard index across uncertainty bins.
  
      Args:
          data: A tuple containing various inputs needed to generate the figures, including:
              - uncertainty_error_pairs (List[Tuple[int, float]]): A list of tuples specifying the uncertainty thresholds
              and corresponding error thresholds to use for binning the data.
              - models_to_compare (List[str]): A list of model names to compare.
              - dataset (str): The name of the dataset being used.
              - target_indices (List[int]): A list of target indices to include in the analysis.
              - num_bins (int): The number of uncertainty bins to use.
              - cmaps (List[str]): A list of colormap names to use for the figures.
              - save_folder (str): The directory in which to save the generated figures.
              - save_file_preamble (str): A string to use as the prefix for the filenames of the generated figures.
              - combine_middle_bins (bool): Whether to combine the middle bins or not.
              - save_figures_bool (bool): Whether to save the generated figures or not. If False, displays instead
              - confidence_invert (bool): Whether to invert the confidence values to uncertainty or not.
              - samples_as_dots_bool (bool): Whether to show individual samples as dots in the box plots or not.
              - show_sample_info_mode (str): The mode for showing sample information in the box plots.
              - box_plot_error_lim (float): The y-axis limit for the error box plots.
              - show_individual_target_plots (bool): Whether to generate separate plots for each individual target.
              - interpret (bool): Whether to perform interpretation analysis i.e. visualization.
              - num_folds (int): The number of folds to use in cross-validation.
              - ind_targets_to_show (List[int]): A list of target indices to include in individual target plots.
              - error_scaling_factor (float, optional): Scaling factor for error. Defaults to 1.0.
  
  
          display_settings: A dictionary containing boolean flags indicating which figures to generate.
  
      Returns:
          None
      """
      logger = logging.getLogger("qbin")
      [
          uncertainty_error_pairs,
          models_to_compare,
          dataset,
          target_indices,
          num_bins,
          cmaps,
          save_folder,
          save_file_preamble,
          combine_middle_bins,
          save_figures_bool,
          confidence_invert,
          samples_as_dots_bool,
          show_sample_info_mode,
          box_plot_error_lim,
          show_individual_target_plots,
          interpret,
          num_folds,
          ind_targets_to_show,
          error_scaling_factor,
      ] = data
  
      # If combining the middle bins we just have the 2 edge bins, and the combined middle ones.
  
      (
          bins_all_targets,
          bins_targets_sep,
          bounds_all_targets,
          bounds_targets_sep,
      ) = generate_struct_for_qbin(
          models_to_compare, target_indices, save_folder, dataset
      )
  
      # Get mean errors bin-wise, get all errors concatenated together bin-wise, and seperate by target.
      all_error_data_dict = get_mean_errors(
          bins_all_targets,
          uncertainty_error_pairs,
          num_bins,
          target_indices,
          num_folds=num_folds,
          error_scaling_factor=error_scaling_factor,
          combine_middle_bins=combine_middle_bins,
      )
      all_error_data = all_error_data_dict["all mean error bins nosep"]
  
      all_bins_concat_targets_nosep_error = all_error_data_dict[
          "all error concat bins targets nosep"
      ]  # shape is [num bins]
  
      all_bins_concat_targets_sep_all_error = all_error_data_dict[
          "all error concat bins targets sep all"
      ]  # same as all_bins_concat_targets_sep_foldwise but folds are flattened to a single list
  
      # Get jaccard
      all_jaccard_data_dict = evaluate_jaccard(
          bins_all_targets,
          uncertainty_error_pairs,
          num_bins,
          target_indices,
          num_folds=num_folds,
          combine_middle_bins=combine_middle_bins,
      )
      all_jaccard_data = all_jaccard_data_dict["Jaccard All"]
      all_recall_data = all_jaccard_data_dict["Recall All"]
      all_precision_data = all_jaccard_data_dict["Precision All"]
  
      all_bins_concat_targets_sep_all_jacc = all_jaccard_data_dict[
          "all jacc concat bins targets sep all"
      ]  # same as all_bins_concat_targets_sep_foldwise but folds are flattened to a single list
  
      bound_return_dict = evaluate_bounds(
          bounds_all_targets,
          bins_all_targets,
          uncertainty_error_pairs,
          num_bins,
          target_indices,
          num_folds,
          combine_middle_bins=combine_middle_bins,
      )
  
      all_bound_data = bound_return_dict["Error Bounds All"]
  
      all_bins_concat_targets_sep_all_errorbound = bound_return_dict[
          "all errorbound concat bins targets sep all"
      ]  # same as all_bins_concat_targets_sep_foldwise but folds are flattened to a single list
  
      generate_summary_df(
          all_error_data_dict,
          [["all mean error bins nosep", "All Targets"]],
          "Mean error",
          os.path.join(save_folder, "target_errors.xlsx"),
      )
  
      if interpret:
          # If we have combined the middle bins, we are only displaying 3 bins (outer edges, and combined middle bins).
          if combine_middle_bins:
              num_bins_display = 3
          else:
              num_bins_display = num_bins
  
          if save_figures_bool:
              save_location = save_folder
          else:
              save_location = None
  
          # Plot piecewise linear regression for error/uncertainty prediction.
          if display_settings["correlation"]:
              _ = evaluate_correlations(
                  bins_all_targets,
                  uncertainty_error_pairs,
                  cmaps,
                  num_bins,
                  confidence_invert,
                  num_folds=num_folds,
                  error_scaling_factor=error_scaling_factor,
                  combine_middle_bins=combine_middle_bins,
                  save_path=save_location,
                  to_log=True,
              )
  
          # Plot cumulative error figure for all predictions
          if display_settings["cumulative_error"]:
              plot_cumulative(
                  cmaps,
                  bins_all_targets,
                  models_to_compare,
                  uncertainty_error_pairs,
                  np.arange(num_bins),
                  "Cumulative error for ALL predictions, dataset "
                  + dataset,
                  save_path=save_location,
                  error_scaling_factor=error_scaling_factor,
              )
              # Plot cumulative error figure for B1 only predictions
              plot_cumulative(
                  cmaps,
                  bins_all_targets,
                  models_to_compare,
                  uncertainty_error_pairs,
                  0,
                  "Cumulative error for B1 predictions, dataset "
                  + dataset,
                  save_path=save_location,
                  error_scaling_factor=error_scaling_factor,
              )
  
              # Plot cumulative error figure comparing B1 and ALL, for both models
              for model_type in models_to_compare:
                  plot_cumulative(
                      cmaps,
                      bins_all_targets,
                      [model_type],
                      uncertainty_error_pairs,
                      0,
                      model_type
                      + ". Cumulative error comparing ALL and B1, dataset "
                      + dataset,
                      compare_to_all=True,
                      save_path=save_location,
                      error_scaling_factor=error_scaling_factor,
                  )
  
          # Set x_axis labels for following plots.
          x_axis_labels = [
              r"$B_{{{}}}$".format(num_bins_display + 1 - (i + 1))
              for i in range(num_bins_display + 1)
          ]
  
          # get error bounds
          if display_settings["errors"]:
              # mean error concat for each bin
              logger.info("mean error concat all L")
              if save_figures_bool:
                  if samples_as_dots_bool:
                      dotted_addition = "_dotted"
                  else:
                      dotted_addition = "_undotted"
                  save_location = os.path.join(
                      save_folder,
                      save_file_preamble
                      + dotted_addition
                      + "_error_all_targets.pdf",
                  )
  
              box_plot_per_model(
                  cmaps,
                  all_bins_concat_targets_nosep_error,
                  uncertainty_error_pairs,
                  models_to_compare,
                  x_axis_labels=x_axis_labels,
                  x_label="Uncertainty Thresholded Bin",
                  y_label="Localization Error (mm)",
                  num_bins=num_bins_display,
                  convert_to_percent=False,
                  show_sample_info=show_sample_info_mode,
                  show_individual_dots=samples_as_dots_bool,
                  y_lim=box_plot_error_lim,
                  to_log=True,
                  save_path=save_location,
              )
  
              if show_individual_target_plots:
                  # plot the concatentated errors for each target seperately
                  for idx_l, target_data in enumerate(
                      all_bins_concat_targets_sep_all_error
                  ):
                      if (
                          idx_l in ind_targets_to_show
                          or ind_targets_to_show == [-1]
                      ):
                          if save_figures_bool:
                              save_location = os.path.join(
                                  save_folder,
                                  save_file_preamble
                                  + dotted_addition
                                  + "_error_target_"
                                  + str(idx_l)
                                  + ".pdf",
                              )
  
                          logger.info("individual error for T%s", idx_l)
  
                          box_plot_per_model(
                              cmaps,
                              target_data,
                              uncertainty_error_pairs,
                              models_to_compare,
                              x_axis_labels=x_axis_labels,
                              x_label="Uncertainty Thresholded Bin",
                              y_label="Error (mm)",
                              num_bins=num_bins_display,
                              convert_to_percent=False,
                              show_sample_info=show_sample_info_mode,
                              show_individual_dots=samples_as_dots_bool,
                              y_lim=box_plot_error_lim,
                              to_log=True,
                              save_path=save_location,
                          )
  
              logger.info("Mean error")
  
              if save_figures_bool:
                  save_location = os.path.join(
                      save_folder,
                      save_file_preamble
                      + dotted_addition
                      + "mean_error_folds_all_targets.pdf",
                  )
  
              box_plot_per_model(
                  cmaps,
                  all_error_data,
                  uncertainty_error_pairs,
                  models_to_compare,
                  x_axis_labels=x_axis_labels,
                  x_label="Uncertainty Thresholded Bin",
                  y_label="Mean Error (mm)",
                  num_bins=num_bins_display,
                  convert_to_percent=False,
                  y_lim=box_plot_error_lim,
                  to_log=True,
                  save_path=save_location,
              )
  
          # Plot Error Bound Accuracy
          if display_settings["error_bounds"]:
              logger.info(" errorbound acc for all targets.")
              if save_figures_bool:
                  save_location = os.path.join(
                      save_folder,
                      save_file_preamble
                      + "_errorbound_all_targets.pdf",
                  )
  
              generic_box_plot_loop(
                  cmaps,
                  all_bound_data,
                  uncertainty_error_pairs,
                  models_to_compare,
                  x_axis_labels=x_axis_labels,
                  x_label="Uncertainty Thresholded Bin",
                  y_label="Error Bound Accuracy (%)",
                  num_bins=num_bins_display,
                  save_path=save_location,
                  y_lim=120,
                  width=0.2,
                  y_lim_min=-2,
                  font_size_1=30,
                  font_size_2=30,
                  show_individual_dots=False,
                  list_comp_bool=False,
              )
  
              if show_individual_target_plots:
                  # plot the concatentated error bounds for each target seperately
                  for idx_l, target_data in enumerate(
                      all_bins_concat_targets_sep_all_errorbound
                  ):
                      if (
                          idx_l in ind_targets_to_show
                          or ind_targets_to_show == [-1]
                      ):
                          if save_figures_bool:
                              save_location = os.path.join(
                                  save_folder,
                                  save_file_preamble
                                  + "_errorbound_target_"
                                  + str(idx_l)
                                  + ".pdf",
                              )
  
                          logger.info(
                              "individual errorbound acc for T%s", idx_l
                          )
  
                          generic_box_plot_loop(
                              cmaps,
                              target_data,
                              uncertainty_error_pairs,
                              models_to_compare,
                              x_axis_labels=x_axis_labels,
                              x_label="Uncertainty Thresholded Bin",
                              y_label="Error Bound Accuracy (%)",
                              num_bins=num_bins_display,
                              save_path=save_location,
                              y_lim=120,
                              width=0.2,
                              y_lim_min=-2,
                              font_size_1=30,
                              font_size_2=30,
                              show_individual_dots=False,
                              list_comp_bool=False,
                          )
  
          # Plot Jaccard Index
          if display_settings["jaccard"]:
              logger.info("Plot jaccard for all targets.")
              if save_figures_bool:
                  save_location = os.path.join(
                      save_folder,
                      save_file_preamble + "_jaccard_all_targets.pdf",
                  )
  
              generic_box_plot_loop(
                  cmaps,
                  all_jaccard_data,
                  uncertainty_error_pairs,
                  models_to_compare,
                  x_axis_labels=x_axis_labels,
                  x_label="Uncertainty Thresholded Bin",
                  y_label="Jaccard Index (%)",
                  num_bins=num_bins_display,
                  save_path=save_location,
                  y_lim=70,
                  width=0.2,
                  y_lim_min=-2,
                  font_size_1=30,
                  font_size_2=30,
                  show_individual_dots=False,
                  list_comp_bool=False,
              )
  
              # mean recall for each bin
              if save_figures_bool:
                  save_location = os.path.join(
                      save_folder,
                      save_file_preamble
                      + "_recall_jaccard_all_targets.pdf",
                  )
  
              generic_box_plot_loop(
                  cmaps,
                  all_recall_data,
                  uncertainty_error_pairs,
                  models_to_compare,
                  x_axis_labels=x_axis_labels,
                  x_label="Uncertainty Thresholded Bin",
                  y_label="Ground Truth Bins Recall",
                  num_bins=num_bins_display,
                  convert_to_percent=True,
                  save_path=save_location,
                  y_lim=120,
                  width=0.2,
                  y_lim_min=-2,
                  font_size_1=30,
                  font_size_2=30,
                  show_individual_dots=False,
                  list_comp_bool=False,
              )
  
              # mean precision for each bin
              if save_figures_bool:
                  save_location = os.path.join(
                      save_folder,
                      save_file_preamble
                      + "_precision_jaccard_all_targets.pdf",
                  )
  
              generic_box_plot_loop(
                  cmaps,
                  all_precision_data,
                  uncertainty_error_pairs,
                  models_to_compare,
                  x_axis_labels=x_axis_labels,
                  x_label="Uncertainty Thresholded Bin",
                  y_label="Ground Truth Bins Precision",
                  num_bins=num_bins_display,
                  convert_to_percent=True,
                  save_path=save_location,
                  y_lim=120,
                  width=0.2,
                  y_lim_min=-2,
                  font_size_1=30,
                  font_size_2=30,
                  show_individual_dots=False,
                  list_comp_bool=False,
              )
  
              if show_individual_target_plots:
                  # plot the jaccard index for each target seperately
  
                  for idx_l, target_data in enumerate(
                      all_bins_concat_targets_sep_all_jacc
                  ):
                      if (
                          idx_l in ind_targets_to_show
                          or ind_targets_to_show == [-1]
                      ):
                          if save_figures_bool:
                              save_location = os.path.join(
                                  save_folder,
                                  save_file_preamble
                                  + "jaccard_target_"
                                  + str(idx_l)
                                  + ".pdf",
                              )
  
                          logger.info(
                              "individual jaccard for T%s", idx_l
                          )
  
                          generic_box_plot_loop(
                              cmaps,
                              target_data,
                              uncertainty_error_pairs,
                              models_to_compare,
                              x_axis_labels=x_axis_labels,
                              x_label="Uncertainty Thresholded Bin",
                              y_label="Jaccard Index (%)",
                              num_bins=num_bins_display,
                              save_path=save_location,
                              y_lim=70,
                              width=0.2,
                              y_lim_min=-2,
                              font_size_1=30,
                              font_size_2=30,
                              show_individual_dots=False,
                              list_comp_bool=False,
                          )
  
imports: import logging
  import math
  import os
  from typing import Any, Dict, List, Optional, Tuple, Union
  import matplotlib.lines
  import matplotlib.patches
  import matplotlib.pyplot
  import matplotlib.ticker
  import numpy
  import pandas
  import pwlf
  from matplotlib.ticker import ScalarFormatter
  from scipy import stats
  from sklearn.isotonic import IsotonicRegression
  from kale.evaluate.similarity_metrics import evaluate_correlations
  from kale.evaluate.uncertainty_metrics import evaluate_bounds, evaluate_jaccard, get_mean_errors
  from kale.prepdata.tabular_transform import generate_struct_for_qbin
  from kale.utils.save_xlsx import generate_summary_df
label_desc: Use image node_id 8 for calling a global function with example usage: generate_fig_individual_bin_comparison(data, display_settings) without return types