docs: def distances(x, y, px, py, plot=False):
      """
      Compute shortest distance of points (px, py) to the line described by the
      end points in (x, y).
  
      Parameters
      ----------
      x,y: x and y coordinates of line
      px: x coordinates of data points
      py: y coordiante of data points
  
      Returns
      -------
      distances: list of distances
      """
  
      length_line = np.sqrt((x[1] - x[0]) ** 2 + (y[1] - y[0]) ** 2)
  
      horizontal = (np.diff(y) == 0)
      vertical = (np.diff(x) == 0)
  
      dist = []
      dpl = []
      counter = 0
      for xp, yp in zip(px, py):
          # compute distances to the end points
          dp = np.sqrt((xp - x) ** 2 + (yp - y) ** 2)
  
          dpl.append(dp)
          if np.any(dp > length_line):
              point_dist = np.min(dp)
          elif horizontal:
              point_dist = np.abs(yp - y[0])
          elif vertical:
              point_dist = np.abs(xp - x[0])
          else:
              nominator = np.abs(
                  (y[1] - y[0]) * xp -
                  (x[1] - x[0]) * yp +
                  x[1] * y[0] -
                  y[1] * x[0])
              denominator = np.sqrt((y[1] - y[0]) ** 2 + (x[1] - x[0]) ** 2)
              point_dist = nominator / denominator
  
          dist.append(point_dist)
          counter += 1
  
      # debug plot
      if plot:
          fig, ax = plt.subplots(1, 1, figsize=(10, 8))
          ax.scatter(x, y)
          ax.scatter(px, py, color='r')
  
          index = 0
          for xp, yp in zip(px, py):
              ax.annotate('{0:.5}, {1:.5}, {2:.5}'.format(
                  dist[index], dpl[index][0], dpl[index][1]),
                  xy=(xp, yp))
              index += 1
          ax.plot(x, y)
          ax.set_aspect('equal')
      return dist