I am vexed by a particular derivation. Given a state $\psi$ and corresponding density matrix $\rho = |\psi\rangle \langle \psi|$, or $\rho = \begin{bmatrix} a & c \\ b & d \end{bmatrix}$, I can compute the Bloch sphere coordinates as the following (in Python):
a = rho[0, 0]
b = rho[1, 0]
x = 2.0 * b.real
y = 2.0 * b.imag
z = 2.0 * a - 1.0
This code works, but - how? I fail to properly derive it. Any hints or pointers are appreciated.