Vertical gradients of sunspot magnetic fields