r'''
Transform absolute y-coordinates to relative y-coordinates. Relative coordinates correspond to a
fraction of the relevant axis. Be sure to set the limits and scale before calling this function!

:arguments:

  **y** (``float``, ``list``)
    Absolute coordinates.

:options:

  **axis** ([``plt.gca()``] | ...)
    Specify the axis to which to apply the limits.

:returns:

  **y** (``float``, ``list``)
    Relative coordinates.

def abs2rel_y(y, axis=None):
  r'''
Transform absolute y-coordinates to relative y-coordinates. Relative coordinates correspond to a
fraction of the relevant axis. Be sure to set the limits and scale before calling this function!

:arguments:

  **y** (``float``, ``list``)
    Absolute coordinates.

:options:

  **axis** ([``plt.gca()``] | ...)
    Specify the axis to which to apply the limits.

:returns:

  **y** (``float``, ``list``)
    Relative coordinates.
  '''

  # get current axis
  if axis is None:
    axis = plt.gca()

  # get current limits
  ymin, ymax = axis.get_ylim()

  # transform
  # - log scale
  if axis.get_xscale() == 'log':
    try   : return [(np.log10(i)-np.log10(ymin))/(np.log10(ymax)-np.log10(ymin)) if i is not None else i for i in y]
    except: return  (np.log10(y)-np.log10(ymin))/(np.log10(ymax)-np.log10(ymin))
  # - normal scale
  else:
    try   : return [(i-ymin)/(ymax-ymin) if i is not None else i for i in y]
    except: return  (y-ymin)/(ymax-ymin)