The heat map is a joint density f(x, y) on the unit square. Adding up each vertical strip gives the marginal density fX(x) (top right, solid); adding up each horizontal strip gives fY (dashed). Cut the surface along the vertical line x = x0 and rescale the slice to have area 1: that is the conditional density f(y | x0) = f(x0, y)/fX(x0) (bottom right). If it keeps the same shape for every x0 the variables are independent; if not, it moves, and so does the conditional mean. The shaded wedge is the event X < cY, whose probability is the volume above it.
Densities: x + y; 2x + y − 2xy; 12xy(1 − y); the constant 2 on the triangle 0 < x < y < 1; and (3/2)(x2 + y2). Probabilities, means and the covariance are computed by numerical integration on a 400 by 400 grid (accurate to about 5 decimals for the smooth densities and 3 for the triangle, whose edge cuts grid cells); the conditional density is exact.
code/ch03_random_variables.py (joint_moments).