code: def plot_sankey(
      data,
      target_col,
      value_cols=None,
      prune_percentile=0.9,
      show_top=5,
      max_categories=5,
      dpi=150,
      figure=None,
  ):
      """Plot sankey diagram based on categorical variable co-occurences.
  
      Actually an alluvian diagram.
  
      Parameters
      ----------
      data : DataFrame
          Input data.
  
      target_col : string
          Target column, used to color flows.
  
      value_cols : list of string
          Column names to include in diagram.
          If none, all categorical columns are considered.
  
      prune_percentile : float, default=.9
          Prune small flows to retain prune_percentile of total weight.
          This will make the plot simpler and faster,
          but might distort the data. In particular, it might hide minority
          populations and only show large trends.
  
      show_top : integer, default=5
          Number of categorical features to show if value_cols is not given.
          Selected based on mutual information.
  
      max_categories : integer, default=5
          Maximum number of categories per variable/column.
          Only the max_categories largest values are considere, the rest is
          grouped into an "other" category.
  
      dpi : integer, default=150
          Resolution for figure. Ignored if figure is passed.
  
      figure : matplotlib figure, default=None
          If passed, dpi is ignored.
  
      """
      if value_cols is None:
          cats = detect_types(data).categorical
          data = data.loc[:, cats].copy()
          for col in data.columns:
              if col == target_col:
                  continue
              data[col] = _prune_categories(
                  data[col], max_categories=max_categories
              )
  
          value_cols = _get_top_features(
              data, target_col, show_top=show_top
          )
      else:
          data = data.copy()
          for col in value_cols:
              data[col] = _prune_categories(
                  data[col], max_categories=max_categories
              )
  
      cols = (
          [target_col] + list(value_cols)
          if target_col is not None
          else value_cols
      )
      data = data[cols]
  
      sizes = data.groupby(data.columns.tolist()).size()
      sizes.name = "weight"
      sankey_data = sizes.reset_index()
      if prune_percentile > 0:
          total = sankey_data.weight.sum()
          vals = sankey_data.weight.sort_values(ascending=False)
          smallest_allowed = vals.iloc[
              np.searchsorted(vals.cumsum(), prune_percentile * total)
          ]
          sankey_data = sankey_data[
              sankey_data.weight >= smallest_allowed
          ]
      if figure is None:
          figure = plt.figure(dpi=dpi, figsize=(len(value_cols) * 2, 6))
      # data_sorted = sankey_data.sort_values(target_col)
      value_cols = [x for x in data.columns if x != target_col]
      alluvian_diagram(
          sankey_data,
          value_cols=value_cols,
          by_col=target_col,
          vertical_margin=0.1,
          horizontal_margin=0.2,
          width=0.05,
          alpha=0.4,
          ax=figure.gca(),
      )
  
file_path: dabl/dabl/plot/sankey.py
imports: import matplotlib
  from collections import defaultdict
  import matplotlib.pyplot
  from matplotlib.path import Path
  import matplotlib.patches
  from itertools import cycle
  from sklearn.feature_selection import mutual_info_classif
  import numpy
  from copy import deepcopy
  from ..preprocessing import detect_types
  from .utils import _prune_categories
label_desc: Use image node_id 4 for calling a global function with example usage: plot_sankey(data, target_col, value_cols, prune_percentile, show_top, max_categories, dpi, figure) without return types