code: def long_tail_plot(
      df,
      item_id_column,
      interaction_type,
      percentage=None,
      x_labels=True,
  ):
      """
      Plots the long tail for a user-item interaction dataset.
      ----------
      df: pandas dataframe
          user-item interaction dataframe
          example:
      item_id_column: str
          column name identifying the item ids in the dataframe
      interaction_type: str
          type of user-item interactions
          i.e. 'purchases', 'ratings' 'interactions', or 'clicks'
      percentage: float, default=None
          percent of volume to consider as the head (percent as a decimal)
          (if default=None no line will be plotted)
      x_tables bool, default=True
          if True, plot x-axis tick labels
          if False, no x-axis tick lavels will be plotted.
      Returns:
      -------
          A long tail plot
      """
      # calculate cumulative volumes
      volume_df = df[item_id_column].value_counts().reset_index()
      volume_df.columns = [item_id_column, "volume"]
      volume_df[item_id_column] = volume_df[item_id_column].astype(str)
      volume_df["cumulative_volume"] = volume_df["volume"].cumsum()
      volume_df["percent_of_total_volume"] = (
          volume_df["cumulative_volume"] / volume_df["volume"].sum()
      )
  
      # line plot of cumulative volume
      x = range(0, len(volume_df))
      ax = sns.lineplot(x=x, y="volume", data=volume_df, color="black")
      plt.xticks(x)
  
      # set labels
      ax.set_title("Long Tail Plot")
      ax.set_ylabel("# of " + interaction_type)
      ax.set_xlabel(item_id_column)
  
      if percentage != None:
          # plot vertical line at the tail location
          head = volume_df[
              volume_df["percent_of_total_volume"] <= percentage
          ]
          tail = volume_df[
              volume_df["percent_of_total_volume"] > percentage
          ]
          items_in_head = len(head)
          items_in_tail = len(tail)
          plt.axvline(x=items_in_head, color="red", linestyle="--")
  
          # fill area under plot
          head = head.append(tail.head(1))
          x1 = head.index.values
          y1 = head["volume"]
          x2 = tail.index.values
          y2 = tail["volume"]
          ax.fill_between(x1, y1, color="blue", alpha=0.2)
          ax.fill_between(x2, y2, color="orange", alpha=0.2)
  
          # create legend
          legend_elements = [
              Line2D(
                  [0],
                  [0],
                  marker="o",
                  color="w",
                  label=str(items_in_head) + ": items in the head",
                  markerfacecolor="blue",
                  markersize=5,
              ),
              Line2D(
                  [0],
                  [0],
                  marker="o",
                  color="w",
                  label=str(items_in_tail) + ": items in the tail",
                  markerfacecolor="orange",
                  markersize=5,
              ),
          ]
          ax.legend(handles=legend_elements, loc=1)
  
      else:
          x1 = volume_df[item_id_column]
          y1 = volume_df["volume"]
          ax.fill_between(x1, y1, color="blue", alpha=0.3)
      if x_labels == False:
          plt.xticks([], [])
          ax.set(xticklabels=[])
      else:
          ax.set_xticklabels(
              labels=volume_df[item_id_column], rotation=45, ha="right"
          )
  
      plt.show()
  
imports: import matplotlib.pyplot
  import numpy
  import pandas
  import plotly.graph_objects
  import seaborn
  from funcsigs import signature
  from matplotlib.lines import Line2D
  from sklearn.metrics import auc, average_precision_score, precision_recall_curve, roc_curve
label_desc: Use image node_id 1 for calling a global function with example usage: long_tail_plot(df, item_id_column, interaction_type, percentage, x_labels) without return types