Why is the CDF of a sample uniformly distributed I read here that given a sample $ X_1,X_2,...,X_n $ from a continuous distribution with cdf $ F_X $, the sample corresponding to $ U_i = F_X(X_i) $ follows a standard uniform distribution.
I have verified this using qualitative simulations in Python, and I was easily able to verify the relationship.
import matplotlib.pyplot as plt
import scipy.stats

xs = scipy.stats.norm.rvs(5, 2, 10000)

fig, axes = plt.subplots(1, 2, figsize=(9, 3))
axes[0].hist(xs, bins=50)
axes[0].set_title("Samples")
axes[1].hist(
    scipy.stats.norm.cdf(xs, 5, 2),
    bins=50
)
axes[1].set_title("CDF(samples)")

Resulting in the following plot:

I am unable to grasp why this happens. I assume it has to do with the definition of the CDF and it's relationship to the PDF, but I am missing something...
I would appreciate it if someone could point me to some reading on the subject or help me get some intuition on the subject.
EDIT: The CDF looks like this:

 A: Here's some intuition. Let's use a discrete example.
Say after an exam the students' scores are $X = [10, 50, 60, 90]$. But you want the scores to be more even or uniform. $h(X) = [25, 50, 75, 100]$ looks better.
One way to achieve this is to find the percentiles of each student's score. Score $10$ is $25\%$, score $50$ is $50\%$, and so on. Note that the percentile is just the CDF. So the CDF of a sample is "uniform".
When $X$ is a random variable, the percentile of $X$ is "uniform" (e.g. the number $X$'s in $0-25$ percentile should be the same as the number of $X$'s in $25-50$ percentile). Therefore the CDF of $X$ is uniformly distributed.
A: Assume $F_X$ is continuous and increasing. Define $Z = F_X(X)$ and note that $Z$ takes values in $[0, 1]$. Then
$$F_Z(x) = P(F_X(X) \leq x) = P(X \leq F_X^{-1}(x)) = F_X(F_X^{-1}(x)) = x.$$
On the other hand, if $U$ is a uniform random variable that takes values in $[0, 1]$,
$$F_U(x) =  \int_R f_U(u)\,du =\int_0^x \,du =x.$$
Thus $F_Z(x) = F_U(x)$ for every $x\in[0, 1]$. Since $Z$ and $U$ has the same distribution function $Z$ must also be uniform on $[0, 1]$.
A: Intuitively, perhaps it makes sense to think of $F(x)$ as a percentile function, e.g. $F(x)$ of a randomly generated sample from the DF $F$ is expected to fall below $x$. Alternately $F^{-1}$ (think inverse images, not a proper inverse function per se) is a "quantile" function. That is, $x = F^{-1}(p)$ is the point $x$ behind which falls $p$ proportion of the sample. The functional composition is measurably commutative $F \circ F^{-1} =_\lambda F^{-1} \circ F$. 
The uniform distribution is the only distribution having a quantile function equal to a percentile function: they are the identity function. So the image space is the same as the probability space. $F$ maps continuous random variables into a (0, 1) space with equal measure. Since for any two percentiles, $a < b$, we have $P(F^{-1}(a) < x < F^{-1}(b)) = P(a < F(X) < b) = b-a$ 
