r'''
Set the limits such that a power-law with a certain exponent lies on the diagonal.

:arguments:

  **exp** (``<float>``)
    The power-law exponent.

  **ll, lr, tl, tr** (``<list>``)
    Coordinates of the lower-left, or the lower-right, or the top-left, or the top-right corner.

  **width, height** (``<float>``)
    Width or the height.

:options:

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

  **plot** ([``False``] | ``True``)
    Plot the diagonal.

  ...
    Any ``plt.plot(...)`` option.

:returns:

  The handle of the ``plt.plot(...)`` command (if any).

def diagonal_powerlaw(exp, ll=None, lr=None, tl=None, tr=None, width=None, height=None, plot=False, **kwargs):
  r'''
Set the limits such that a power-law with a certain exponent lies on the diagonal.

:arguments:

  **exp** (``<float>``)
    The power-law exponent.

  **ll, lr, tl, tr** (``<list>``)
    Coordinates of the lower-left, or the lower-right, or the top-left, or the top-right corner.

  **width, height** (``<float>``)
    Width or the height.

:options:

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

  **plot** ([``False``] | ``True``)
    Plot the diagonal.

  ...
    Any ``plt.plot(...)`` option.

:returns:

  The handle of the ``plt.plot(...)`` command (if any).
  '''

  axis = kwargs.pop('axis', plt.gca())

  if   width  and not height: width  = np.log(width )
  elif height and not width : height = np.log(height)
  else: raise IOError('Specify "width" or "height"')

  if   ll and not lr and not tl and not tr: ll = [ np.log(ll[0]), np.log(ll[1]) ]
  elif lr and not ll and not tl and not tr: lr = [ np.log(lr[0]), np.log(lr[1]) ]
  elif tl and not lr and not ll and not tr: tl = [ np.log(tl[0]), np.log(tl[1]) ]
  elif tr and not lr and not tl and not ll: tr = [ np.log(tr[0]), np.log(tr[1]) ]
  else: raise IOError('Specify "ll" or "lr" or "tl" or "tr"')

  axis.set_xscale('log')
  axis.set_yscale('log')

  if   width : height = width  * np.abs(exp)
  elif height: width  = height / np.abs(exp)

  if ll:
    axis.set_xlim(sorted([np.exp(ll[0]), np.exp(ll[0]+width )]))
    axis.set_ylim(sorted([np.exp(ll[1]), np.exp(ll[1]+height)]))
  elif lr:
    axis.set_xlim(sorted([np.exp(lr[0]), np.exp(lr[0]-width )]))
    axis.set_ylim(sorted([np.exp(lr[1]), np.exp(lr[1]+height)]))
  elif tl:
    axis.set_xlim(sorted([np.exp(tl[0]), np.exp(tl[0]+width )]))
    axis.set_ylim(sorted([np.exp(tl[1]), np.exp(tl[1]-height)]))
  elif tr:
    axis.set_xlim(sorted([np.exp(tr[0]), np.exp(tr[0]-width )]))
    axis.set_ylim(sorted([np.exp(tr[1]), np.exp(tr[1]-height)]))

  if plot:
    if exp > 0: return plot_powerlaw(exp, 0., 0., 1., **kwargs)
    else      : return plot_powerlaw(exp, 0., 1., 1., **kwargs)