code: def bar_stack(
      data,
      ax=None,
      labels=None,
      ticks=None,
      colors=None,
      colormap=None,
      orientation="vertical",
      legend=True,
      legend_kws=None,
      **kwargs,
  ):
      """
      An advanced bar chart plotting utility that can draw bar and stacked bar charts from
      data, wrapping calls to the specified matplotlib.Axes object.
  
      Parameters
      ----------
      data : 2D array-like
          The data passed to the Visualizer. Rows represent each stack in the bar chart and columns
          represent each bar. Therefore, a single bar chart is created by passing a 2D array
          containing a single row, while the data to create a bar chart with 3 stacks would have a
          shape of (3, b).
  
      ax : matplotlib.Axes, default: None
          The axes object to draw the barplot on, uses plt.gca() if not specified.
  
      labels : list of str, default: None
          The labels for each row in the bar stack, used to create a legend.
  
      ticks : list of str, default: None
          The labels for each bar, added to the x-axis for a vertical plot, or the y-axis
          for a horizontal plot.
  
      colors : array-like, default: None
          Specify the colors of each bar, each row in the stack, or every segment.
  
      colormap : string or matplotlib cmap
          Specify a colormap for each bar, each row in the stack, or every segment.
  
      orientation:‘vertical’ or ‘horizontal’
          Specifies a horizontal or vertical bar chart.
  
      legend : boolean, default: True
          If True, the function add a legend with the plot
  
      legend_kws : dict, default: None
          Additional keyword arguments for the legend components.
  
      kwargs : dict
          Additional keyword arguments to pass to ``ax.bar``.
      """
      if ax is None:
          ax = plt.gca()
  
      colors = resolve_colors(
          n_colors=data.shape[0], colormap=colormap, colors=colors
      )
  
      idx = np.arange(data.shape[1])
      zeros = np.zeros(data.shape[1])
      # Stores stacks for both side of plotting axes
      stack_arr = np.zeros((data.shape[1], 2))
      orientation = orientation.lower()
  
      if orientation.startswith("h"):
          for rdx in range(len(data)):
              stack = [
                  stack_arr[j, int(data[rdx][j] > 0)]
                  for j in range(len(data[rdx]))
              ]
              ax.barh(idx, data[rdx], left=stack, color=colors[rdx])
              # Updates the stack for negative side of y-axis
              stack_arr[:, 0] += np.minimum(data[rdx], zeros)
              # Updates stack for positive side of y-axis
              stack_arr[:, 1] += np.maximum(data[rdx], zeros)
          ax.set_yticks(idx)
          if ticks is not None:
              ax.set_yticklabels(ticks)
  
      elif orientation.startswith("v"):
          for rdx in range(len(data)):
              stack = [
                  stack_arr[j, int(data[rdx][j] > 0)]
                  for j in range(len(data[rdx]))
              ]
              ax.bar(idx, data[rdx], bottom=stack, color=colors[rdx])
              # Updates the stack for negative side of x-axis
              stack_arr[:, 0] += np.minimum(data[rdx], zeros)
              # Updates the stack for negative side of x-axis
              stack_arr[:, 1] += np.maximum(data[rdx], zeros)
          ax.set_xticks(idx)
          if ticks is not None:
              ax.set_xticklabels(ticks, rotation=90)
  
      else:
          raise YellowbrickValueError(
              "unknown orientation '{}'".format(orientation)
          )
  
      # Generates default labels is labels are not specified.
      labels = labels or np.arange(data.shape[0])
  
      if legend:
          legend_kws = legend_kws or {}
          manual_legend(ax, labels=labels, colors=colors, **legend_kws)
      return ax
  
file_path: yellowbrick/yellowbrick/draw.py
imports: from .base import Visualizer
  from .exceptions import YellowbrickValueError
  from .style.colors import resolve_colors
  from matplotlib import patches
  import matplotlib.pyplot
  import numpy
label_desc: Use image node_id 2 for calling a global function with example usage: bar_stack(data, ax, labels, ticks, colors, colormap, orientation, legend, legend_kws) and returns: ax