class_docstr: SmartPlotter is a Bridge pattern decoupling plotting functions from SmartExplainer.
  The smartplotter class includes all the methods used to display graphics
  Each SmartPlotter method is easy to use from a Smart explainer object,
  just use the following syntax
  Attributes :
  explainer: object
      SmartExplainer instance to point to.
  Example
  --------
  >>> xpl.plot.my_plot_method(param=value)
class_docstr_tok: ["SmartPlotter","is","a","Bridge","pattern","decoupling","plotting","functions","from","SmartExplainer",".","The","smartplotter","class","includes","all","the","methods","used","to","display","graphics","Each","SmartPlotter","method","is","easy","to","use","from","a","Smart","explainer","object",",","just","use","the","following","syntax","Attributes",":","explainer",":","object","SmartExplainer","instance","to","point","to",".","Example","--","--","--","--",">",">",">","xpl.plot.my_plot_method","(","param=value",")"]
docstr: Plotly comparison plot of several individuals' contributions. Plots contributions feature by feature.
  Allows to see the differences of contributions between two or more individuals,
  with each individual represented by a unique line.
  Parameters
  ----------
  index: list
      1st option to select individual rows.
      Int list of index referencing rows.
  row_num: list
      2nd option to select individual rows.
      int list corresponding to the row numbers of individuals (starting at 0).
  label: int or string (default: None)
      If the label is of string type, check if it can be changed to integer to select the
      good dataframe object.
  max_features: int (optional, default: 20)
      Number of contributions to show.
      If greater than the total of features, shows all.
  width: int (default: 900)
      Plotly figure - layout width.
  height: int (default: 550)
      Plotly figure - layout height.
  show_predict: boolean (default: True)
      Shows predict or predict_proba value.
  file_name: string (optional)
      File name to use to save the plotly bar chart. If None the bar chart will not be saved.
  auto_open: boolean (optional)
      Indicates whether to open the bar plot or not.
  Returns
  -------
  Plotly Figure Object
      Comparison plot of the contributions of the different individuals.
  Example
  -------
  >>> xpl.plot.compare_plot(row_num=[0, 1, 2])
code: def compare_plot(
      self,
      index=None,
      row_num=None,
      label=None,
      max_features=20,
      width=900,
      height=550,
      show_predict=True,
      file_name=None,
      auto_open=True,
  ):
      """
      Plotly comparison plot of several individuals' contributions. Plots contributions feature by feature.
      Allows to see the differences of contributions between two or more individuals,
      with each individual represented by a unique line.
      Parameters
      ----------
      index: list
          1st option to select individual rows.
          Int list of index referencing rows.
      row_num: list
          2nd option to select individual rows.
          int list corresponding to the row numbers of individuals (starting at 0).
      label: int or string (default: None)
          If the label is of string type, check if it can be changed to integer to select the
          good dataframe object.
      max_features: int (optional, default: 20)
          Number of contributions to show.
          If greater than the total of features, shows all.
      width: int (default: 900)
          Plotly figure - layout width.
      height: int (default: 550)
          Plotly figure - layout height.
      show_predict: boolean (default: True)
          Shows predict or predict_proba value.
      file_name: string (optional)
          File name to use to save the plotly bar chart. If None the bar chart will not be saved.
      auto_open: boolean (optional)
          Indicates whether to open the bar plot or not.
      Returns
      -------
      Plotly Figure Object
          Comparison plot of the contributions of the different individuals.
      Example
      -------
      >>> xpl.plot.compare_plot(row_num=[0, 1, 2])
      """
      # Checking input is okay
      if sum(arg is not None for arg in [row_num, index]) != 1:
          raise ValueError(
              "You have to specify just one of these arguments: index, row_num"
          )
      # Getting indexes in a list
      line_reference = []
      if index is not None:
          for ident in index:
              if ident in self.explainer.x_init.index:
                  line_reference.append(ident)
  
      elif row_num is not None:
          line_reference = [
              self.explainer.x_init.index.values[row_nb_reference]
              for row_nb_reference in row_num
              if self.explainer.x_init.index.values[row_nb_reference]
              in self.explainer.x_init.index
          ]
  
      subtitle = ""
      if len(line_reference) < 1:
          raise ValueError("No matching entry for index")
  
      # Classification case
      if self.explainer._case == "classification":
          if label is None:
              label = -1
  
          label_num, _, label_value = self.explainer.check_label_name(
              label
          )
          contrib = self.explainer.contributions[label_num]
  
          if show_predict:
              preds = [
                  self.local_pred(line, label_num)
                  for line in line_reference
              ]
              subtitle = (
                  f"Response: <b>{label_value}</b> - "
                  + "Probas: "
                  + " ; ".join(
                      [
                          str(id)
                          + ": <b>"
                          + str(round(proba, 2))
                          + "</b>"
                          for proba, id in zip(preds, line_reference)
                      ]
                  )
              )
  
      # Regression case
      elif self.explainer._case == "regression":
          contrib = self.explainer.contributions
  
          if show_predict:
              preds = [self.local_pred(line) for line in line_reference]
              subtitle = "Predictions: " + " ; ".join(
                  [
                      str(id) + ": <b>" + str(round(pred, 2)) + "</b>"
                      for id, pred in zip(line_reference, preds)
                  ]
              )
  
      new_contrib = list()
      for ident in line_reference:
          new_contrib.append(contrib.loc[ident])
      new_contrib = np.array(new_contrib).T
  
      # Well labels if available
      feature_values = [0] * len(contrib.columns)
      if hasattr(self.explainer, "columns_dict"):
          for i, name in enumerate(contrib.columns):
              feature_name = self.explainer.features_dict[name]
              feature_values[i] = feature_name
  
      preds = [self.explainer.x_init.loc[id] for id in line_reference]
      dict_features = self.explainer.inv_features_dict
  
      iteration_list = list(zip(new_contrib, feature_values))
      iteration_list.sort(
          key=lambda x: maximum_difference_sort_value(x), reverse=True
      )
      iteration_list = iteration_list[:max_features]
      iteration_list = iteration_list[::-1]
      new_contrib, feature_values = list(zip(*iteration_list))
  
      fig = self.plot_line_comparison(
          line_reference,
          feature_values,
          new_contrib,
          predictions=preds,
          dict_features=dict_features,
          width=width,
          height=height,
          subtitle=subtitle,
          file_name=file_name,
          auto_open=auto_open,
      )
  
      return fig
  
imports: import warnings
  from numbers import Number
  import random
  import copy
  import math
  import numpy
  from scipy.optimize import fsolve
  import scipy.cluster.hierarchy
  import pandas
  from plotly import graph_objs
  import plotly.express
  from plotly.subplots import make_subplots
  from plotly.offline import plot
  from shapash.manipulation.select_lines import select_lines
  from shapash.manipulation.summarize import compute_features_import, project_feature_values_1d, compute_corr
  from shapash.utils.utils import add_line_break, truncate_str, compute_digit_number, add_text, maximum_difference_sort_value, compute_sorted_variables_interactions_list_indices, compute_top_correlations_features
  from shapash.webapp.utils.utils import round_to_k
  from shapash.style.style_utils import colors_loading, select_palette, define_style
label_desc: Use image node_id 18 for calling the SmartPlotter obj's underlying member method code with example usage: obj.compare_plot(index, row_num, label, max_features, width, height, show_predict, file_name, auto_open) and returns: fig