code: def plot_tsne(
      token_evaluated,
      tsne_table,
      color_summary_val,
      layer_slider_val,
      selected_rows,
      color_summary_val_to_col,
      val_to_label,
  ):
      x = f"layer_{layer_slider_val:02}_tsne_x"
      y = f"layer_{layer_slider_val:02}_tsne_y"
  
      figure = go.Figure()
  
      # Continuous variable plotting
      if val_to_label is None:
          figure.add_trace(
              go.Scatter(
                  x=tsne_table[x],
                  y=tsne_table[y],
                  hovertext=tsne_table[token_evaluated].astype("str"),
                  mode="markers",
                  marker=dict(
                      color=tsne_table[
                          color_summary_val_to_col[color_summary_val]
                      ],
                      colorscale="Jet",
                      showscale=True,
                      cmin=-1.0
                      if color_summary_val.find("delta") != -1
                      else 0.0,
                      cmax=1.0,
                  ),
                  name=color_summary_val,
                  showlegend=True,
              )
          )
          figure.add_trace(
              go.Scatter(
                  x=selected_rows[x],
                  y=selected_rows[y],
                  mode="markers+text",
                  hovertext=selected_rows[token_evaluated].astype(
                      "str"
                  ),
                  text=selected_rows[token_evaluated].astype("str"),
                  textposition="top center",
                  textfont=dict(size=15),
                  marker=dict(
                      color="orange",
                      colorscale="Jet",
                      showscale=False,
                      symbol="star",
                      size=10,
                      opacity=1,
                      cmin=-1.0
                      if color_summary_val.find("delta") != -1
                      else 0.0,
                      cmax=1.0,
                  ),
                  showlegend=False,
              )
          )
          figure.update_layout(
              legend=dict(font=dict(size=15), y=1.1, x=0.9)
          )
  
      # Discrete/categorical plotting
      else:
          for val in sorted(
              tsne_table[
                  color_summary_val_to_col[color_summary_val]
              ].unique(),
              reverse=True,
          ):
              curr_trace_df = tsne_table[
                  tsne_table[
                      color_summary_val_to_col[color_summary_val]
                  ]
                  == val
              ]
              figure.add_trace(
                  go.Scatter(
                      x=curr_trace_df[x],
                      y=curr_trace_df[y],
                      hovertext=curr_trace_df[token_evaluated].astype(
                          "str"
                      ),
                      mode="markers",
                      name=val_to_label[val],
                  )
              )
  
          figure.add_trace(
              go.Scatter(
                  x=selected_rows[x],
                  y=selected_rows[y],
                  hovertext=selected_rows[token_evaluated].astype(
                      "str"
                  ),
                  mode="markers+text",
                  text=selected_rows[token_evaluated].astype("str"),
                  textposition="top center",
                  textfont=dict(size=15),
                  marker=dict(
                      color="orange",
                      symbol="star",
                      size=10,
                  ),
                  name="Selected Sentence",
              )
          )
          figure.update_layout(legend_x=0, legend_y=1)
  
      figure.update_layout(margin={"l": 0, "r": 0, "b": 60, "t": 20})
      return figure
  
file_path: nlp-architect/solutions/InterpreT/application/plotFunc.py
imports: import base64
  import copy
  from io import BytesIO
  import numpy
  import matplotlib.pyplot
  import plotly.graph_objects
label_desc: Use image node_id 2 for calling a global function with example usage: plot_tsne(token_evaluated, tsne_table, color_summary_val, layer_slider_val, selected_rows, color_summary_val_to_col, val_to_label) and returns: figure