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: The local_plot method is used to display the local contributions of
  an individual in the dataset.
  The plot returned is a summary of local explainability.
  you could use the method filter beforehand to modify the parameters of this summary.
  preprocessing is used here to make this graph more intelligible
  index, row_num or query parameter can be used to select the local explanations to display
  local_plot tutorial offers a lot of examples (please check tutorial part of this doc)
  Parameters
  ----------
  index: string, int, float, ... type of index in x_val input matrix (default None)
      1rst option, to select a row whose local contribution will be displayed.
      Use this parameter to select a row by index
  row_num: int (default None)
      2nd option, specify the row number to select the row whose local
      contribution will be displayed.
  query: string
      3rd option: Boolean condition that must filter only one line of the prediction
      set before plotting.
  label: integer 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.
  show_masked: bool (default: False)
      show the sum of the contributions of the hidden variable
  show_predict: bool (default: True)
      show predict or predict proba value
  yaxis_max_label: int
      Maximum number of variables to display labels on the y axis
  display_groups : bool (default: None)
      Whether or not to display groups of features. This option is
      only useful if groups of features are declared when compiling
      SmartExplainer object.
  width : Int (default: 900)
      Plotly figure - layout width
  height : Int (default: 550)
      Plotly figure - layout height
  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)
      Indicate whether to open the bar plot or not.
  zoom: bool (default=False)
      graph is currently zoomed
  Returns
  -------
  Plotly Figure Object
      Input arrays updated with masked contributions.
  Example
  --------
  >>> xpl.plot.local_plot(row_num=0)
code: def local_plot(
      self,
      index=None,
      row_num=None,
      query=None,
      label=None,
      show_masked=True,
      show_predict=True,
      display_groups=None,
      yaxis_max_label=12,
      width=900,
      height=550,
      file_name=None,
      auto_open=False,
      zoom=False,
  ):
      """
      The local_plot method is used to display the local contributions of
      an individual in the dataset.
      The plot returned is a summary of local explainability.
      you could use the method filter beforehand to modify the parameters of this summary.
      preprocessing is used here to make this graph more intelligible
      index, row_num or query parameter can be used to select the local explanations to display
      local_plot tutorial offers a lot of examples (please check tutorial part of this doc)
      Parameters
      ----------
      index: string, int, float, ... type of index in x_val input matrix (default None)
          1rst option, to select a row whose local contribution will be displayed.
          Use this parameter to select a row by index
      row_num: int (default None)
          2nd option, specify the row number to select the row whose local
          contribution will be displayed.
      query: string
          3rd option: Boolean condition that must filter only one line of the prediction
          set before plotting.
      label: integer 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.
      show_masked: bool (default: False)
          show the sum of the contributions of the hidden variable
      show_predict: bool (default: True)
          show predict or predict proba value
      yaxis_max_label: int
          Maximum number of variables to display labels on the y axis
      display_groups : bool (default: None)
          Whether or not to display groups of features. This option is
          only useful if groups of features are declared when compiling
          SmartExplainer object.
      width : Int (default: 900)
          Plotly figure - layout width
      height : Int (default: 550)
          Plotly figure - layout height
      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)
          Indicate whether to open the bar plot or not.
      zoom: bool (default=False)
          graph is currently zoomed
      Returns
      -------
      Plotly Figure Object
          Input arrays updated with masked contributions.
      Example
      --------
      >>> xpl.plot.local_plot(row_num=0)
      """
      display_groups = (
          True
          if (
              display_groups is not False
              and self.explainer.features_groups is not None
          )
          else False
      )
      if display_groups:
          data = self.explainer.data_groups
      else:
          data = self.explainer.data
  
      if index is not None:
          if index in self.explainer.x_init.index:
              line = [index]
          else:
              line = []
      elif row_num is not None:
          line = [self.explainer.x_init.index[row_num]]
      elif query is not None:
          line = select_lines(self.explainer.x_init, query)
      else:
          line = []
  
      subtitle = ""
  
      if len(line) != 1:
          if len(line) > 1:
              raise ValueError(
                  "Only one line/observation must match the condition"
              )
          contrib = []
          x_val = []
          var_dict = []
  
      else:
          # apply filter if the method have not yet been asked in order to limit the number of feature to display
          if (
              not hasattr(
                  self.explainer, "mask_params"
              )  # If the filter method has not been called yet
              # Or if the already computed mask was not updated with current display_groups parameter
              or (
                  isinstance(data["contrib_sorted"], pd.DataFrame)
                  and len(data["contrib_sorted"].columns)
                  != len(self.explainer.mask.columns)
              )
              or (
                  isinstance(data["contrib_sorted"], list)
                  and len(data["contrib_sorted"][0].columns)
                  != len(self.explainer.mask[0].columns)
              )
          ):
              self.explainer.filter(
                  max_contrib=20, display_groups=display_groups
              )
  
          if self.explainer._case == "classification":
              if label is None:
                  label = -1
  
              (
                  label_num,
                  _,
                  label_value,
              ) = self.explainer.check_label_name(label)
  
              contrib = data["contrib_sorted"][label_num]
              x_val = data["x_sorted"][label_num]
              var_dict = data["var_dict"][label_num]
  
              if show_predict is True:
                  pred = self.local_pred(line[0], label_num)
                  if pred is None:
                      subtitle = f"Response: <b>{label_value}</b> - No proba available"
                  else:
                      subtitle = f"Response: <b>{label_value}</b> - Proba: <b>{pred:.4f}</b>"
  
          elif self.explainer._case == "regression":
              contrib = data["contrib_sorted"]
              x_val = data["x_sorted"]
              var_dict = data["var_dict"]
              label_num = None
              if show_predict is True:
                  pred_value = self.local_pred(line[0])
                  if self.explainer.y_pred is not None:
                      if self.round_digit is None:
                          self.tuning_round_digit()
                      digit = self.round_digit
                  else:
                      digit = compute_digit_number(pred_value)
                  subtitle = (
                      f"Predict: <b>{round(pred_value, digit)}</b>"
                  )
  
          var_dict, x_val, contrib = self.get_selection(
              line, var_dict, x_val, contrib
          )
          var_dict, x_val, contrib = self.apply_mask_one_line(
              line, var_dict, x_val, contrib, label=label_num
          )
          # use label of each column
          if display_groups:
              var_dict = [
                  self.explainer.features_dict[
                      self.explainer.x_init_groups.columns[x]
                  ]
                  for x in var_dict
              ]
          else:
              var_dict = [
                  self.explainer.features_dict[
                      self.explainer.columns_dict[x]
                  ]
                  for x in var_dict
              ]
          if show_masked:
              (
                  var_dict,
                  x_val,
                  contrib,
              ) = self.check_masked_contributions(
                  line, var_dict, x_val, contrib, label=label_num
              )
          # Filtering all negative or positive contrib if specify in mask
          exclusion = []
          if hasattr(self.explainer, "mask_params"):
              if self.explainer.mask_params["positive"] is True:
                  exclusion = np.where(np.array(contrib) < 0)[
                      0
                  ].tolist()
              elif self.explainer.mask_params["positive"] is False:
                  exclusion = np.where(np.array(contrib) > 0)[
                      0
                  ].tolist()
          exclusion.sort(reverse=True)
          for expl in exclusion:
              del var_dict[expl]
              del x_val[expl]
              del contrib[expl]
  
      fig = self.plot_bar_chart(
          line,
          var_dict,
          x_val,
          contrib,
          yaxis_max_label,
          subtitle,
          width,
          height,
          file_name,
          auto_open,
          zoom,
      )
      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 14 for calling the SmartPlotter obj's underlying member method code with example usage: obj.local_plot(index, row_num, query, label, show_masked, show_predict, display_groups, yaxis_max_label, width, height, file_name, auto_open, zoom) and returns: fig