from PIL import ImageDraw


def line(pos, image, data, scale=1, spacing=3, mode='dual'):
  """
  Draw spectrum bars.
  :param pos: (x, y) - position of spectrum on image
  :param image: PIL.image - image to draw
  :param data: 1D array - spectrum data
  :param scale: number - scaling of bar lenght
  :param spacing: int - spacing between bars
  :param mode: dual | bottom | up - direction of bars
  """
  im = image.copy()
  x, y = pos
  for i, l in enumerate(data):
    tall = l * scale
    xx = x + i * spacing
    if mode == 'bottom':
      y1 = y + tall
      y2 = y
    elif mode == 'up':
      y1 = y
      y2 = y - tall
    else:
      y1 = y + tall
      y2 = y - tall
    ImageDraw.Draw(im).line((xx, y1, xx, y2))
  return im