# State Visualization **State visualization** displays quantum states and operators for understanding and debugging. QuTiP provides plotting functions for populations, densities, Wigner functions, and more. ## Populations and Occupations Plot populations (diagonal elements of density matrix): ```python from qutip import * import matplotlib.pyplot as plt # Time evolution of a damped qubit H = 0.5 * sigmaz() c_ops = [0.1 * sigmam()] times = np.linspace(0, 10, 100) psi0 = basis(2, 1) result = mesolve(H, psi0, times, c_ops, [sigmaz()]) # Plot expectation values fig, ax = plt.subplots() ax.plot(times, result.expect[0], 'b-', label='<σ_z>') ax.set_xlabel('Time') ax.set_ylabel('Expectation Value') ax.legend() plt.show() ``` ## Density Matrix Heatmap Visualize density matrix elements: ```python rho = mesolve(H, psi0, [0, 5], c_ops, []).states[-1] # Heatmap of |ρ_ij| fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 4)) ax1.imshow(np.abs(rho.full())) ax1.set_title('|ρ|') ax2.imshow(np.angle(rho.full())) ax2.set_title('arg(ρ)') plt.show() ``` ## Wigner Function For harmonic oscillators, the Wigner function is a quasi-probability on phase space: ```python # Coherent state N = 20 # Hilbert space dimension alpha = 2.0 psi = coherent(N, alpha) # Wigner function xvec = np.linspace(-4, 4, 200) W = wigner(psi, xvec, xvec) fig, ax = plt.subplots() contourf = ax.contourf(xvec, xvec, W, levels=20) ax.set_xlabel('Re(α)') ax.set_ylabel('Im(α)') plt.colorbar(contourf) plt.show() ``` Visualization is essential for understanding quantum dynamics and debugging simulations.