def _line_labels(last, pos='value', sep=1, delta=0.1, max_iters=20):
  """Calculate y-position of line labels, minimizing label overlap."""
  labels = last.copy()
  for _ in range(max_iters):
    changed = False
    for i, row_i in labels.iterrows():
      for j, row_j in labels.iterrows():
        if j <= i: continue
        pos_i = row_i[pos]
        pos_j = row_j[pos]
        if abs(pos_i - pos_j) < sep:
          if pos_i < pos_j:
            labels.at[i, pos] -= delta
            labels.at[j, pos] += delta
          else:
            labels.at[i, pos] += delta
            labels.at[j, pos] -= delta
          changed = True
    if not changed: break
  return labels