code: def plotly_precision_plot(
      precision_df, cutoff=None, labels=None, pos_label=None
  ):
      """Returns a plotly figure with average predicted probability and
      percentage positive per probability bin.
  
      Args:
          precision_df (pd.DataFrame): generated with get_precision_df(..)
          cutoff (float, optional): Model cutoff to display in graph. Defaults to None.
          labels (List[str], optional): Labels for prediction classes. Defaults to None.
          pos_label (int, optional): For multiclass classifiers: which class to treat
          as positive class. Defaults to None.
  
      Returns:
          Plotly fig
      """
  
      label = (
          labels[pos_label]
          if labels is not None and pos_label is not None
          else "positive"
      )
  
      precision_df = precision_df.copy()
  
      spacing = 0.1 / len(precision_df)
      bin_widths = precision_df["bin_width"] - spacing
      bin_widths[bin_widths < 0.005] = 0.005
  
      trace1 = go.Bar(
          x=(
              0.5 * (precision_df["p_min"] + precision_df["p_max"])
          ).values,
          y=precision_df["count"].values,
          width=bin_widths.values.astype("float"),
          name="counts",
      )
  
      data = [trace1]
  
      if "precision_0" in precision_df.columns.tolist():
          # if a pred_proba with probability for every class gets passed
          # to get_precision_df, it generates a precision for every class
          # in every bin as well.
          precision_cols = [
              col
              for col in precision_df.columns.tolist()
              if col.startswith("precision_")
          ]
          if labels is None:
              labels = [
                  "class " + str(i) for i in range(len(precision_cols))
              ]
          if pos_label is not None:
              # add the positive class first with thick line
              trace = go.Scatter(
                  x=precision_df["p_avg"].values.tolist(),
                  y=precision_df[
                      "precision_" + str(pos_label)
                  ].values.tolist(),
                  name=labels[pos_label] + "(positive class)",
                  line=dict(width=4),
                  yaxis="y2",
              )
              data.append(trace)
  
          for i, precision_col in enumerate(precision_cols):
              # add the rest of the classes with thin lines
              if pos_label is None or i != pos_label:
                  trace = go.Scatter(
                      x=precision_df["p_avg"].values.tolist(),
                      y=precision_df[precision_col].values.tolist(),
                      name=labels[i],
                      line=dict(width=2),
                      yaxis="y2",
                  )
                  data.append(trace)
      else:
          trace2 = go.Scatter(
              x=precision_df["p_avg"].values.tolist(),
              y=precision_df["precision"].values.tolist(),
              name="percentage " + label,
              yaxis="y2",
          )
          data = [trace1, trace2]
  
      layout = go.Layout(
          title=f"percentage {label} vs predicted probability",
          yaxis=dict(title="counts"),
          yaxis2=dict(
              title="percentage",
              titlefont=dict(color="rgb(148, 103, 189)"),
              tickfont=dict(color="rgb(148, 103, 189)"),
              overlaying="y",
              side="right",
              rangemode="tozero",
          ),
          xaxis=dict(title="predicted probability"),
          plot_bgcolor="#fff",
      )
  
      if cutoff is not None:
          layout["shapes"] = [
              dict(
                  type="line",
                  xref="x",
                  yref="y2",
                  x0=cutoff,
                  x1=cutoff,
                  y0=0,
                  y1=1.0,
              )
          ]
  
      fig = go.Figure(data=data, layout=layout)
      fig.update_layout(
          legend=dict(orientation="h", xanchor="center", y=-0.2, x=0.5),
          margin=dict(t=40, b=40, l=40, r=40),
      )
      if cutoff is not None:
          fig.update_layout(
              annotations=[
                  go.layout.Annotation(
                      x=cutoff,
                      y=0.1,
                      yref="y2",
                      text=f"cutoff={cutoff}",
                  )
              ]
          )
      return fig
  
imports: import warnings
  import numpy
  import pandas
  from pandas.api.types import is_numeric_dtype
  import plotly.graph_objs
  from plotly.subplots import make_subplots
  from sklearn.metrics import classification_report, confusion_matrix, precision_recall_curve, roc_curve, roc_auc_score, average_precision_score
  from .explainer_methods import matching_cols, safe_isinstance
label_desc: Use image node_id 3 for calling a global function with example usage: plotly_precision_plot(precision_df, cutoff, labels, pos_label) and returns: fig