PDF and CDF

Compare density and cumulative curves for uniform, exponential, normal and beta distributions

Intermediate
Distribution
Probability

PDF f(x)(shaded area = probability)

0.00.10.2mean-10.0-7.5-5.0-2.50.02.55.07.510.0ab

CDF F(x) = P(X ≤ x)(highlighted height = same probability)

0.000.250.500.751.00-10.0-7.5-5.0-2.50.02.55.07.510.0ab

Drag on either chart to move the nearest marker. Both charts share the same x-axis.

Probability
P(-1.00 ≤ X ≤ 2.00)
0.6563
F(a), F at a = -1.00
0.2525
F(b), F at b = 2.00
0.9088
Density f(a), not a probability
0.2130

area = F(b) − F(a) = 0.9088 − 0.2525

Summary
Mean
0.000
Median
0.000
Variance
2.250
Std. dev.
1.500

f(x) = e^(−(x − μ)² / (2σ²)) / (σ√(2π))

F(x) = Φ((x − μ) / σ) = ½[1 + erf((x − μ) / (σ√2))]

Quantile (inverse CDF)
x with F(x) = 0.9
1.9223

90.0% of the probability lies below this value: it is the 90.0th percentile.

Density and cumulative probability

A continuous random variable, like a waiting time or a measurement, can take any value in an interval. There are infinitely many such values, so the chance of hitting any one of them exactly is zero. Instead of listing probabilities, we describe X with a probability density function f(x): the probability that X lands in an interval is the area under f over that interval.

The cumulative distribution function F(x) = P(X ≤ x) records that area as a running total from the left. It answers every interval question with a subtraction: P(a ≤ X ≤ b) = F(b) − F(a). The visualizer shows this side by side: the shaded area on the PDF and the highlighted rise on the CDF are always the same number.

Going the other way, from a probability to a value, is the job of the quantile function F⁻¹(p). It gives medians, percentiles and the critical values used in confidence intervals and hypothesis tests. For the uniform and exponential it has a simple formula; for the normal, beta and gamma it is computed numerically, here by bisection on an accurate CDF.

Density, not probability

For a continuous X, P(X = x) is 0 for every single x. The PDF f(x) is probability per unit length, so only areas under it are probabilities, and f(x) itself can be larger than 1.

CDF is the running total

F(x) = P(X ≤ x) adds up all the area to the left of x. It climbs from 0 to 1, never decreases, and is steepest where the density is highest.

Two views of one thing

The PDF is the slope of the CDF, and the CDF is the area under the PDF. The probability of an interval is an area on one chart and a height difference on the other.

Quantiles invert the CDF

The p-quantile is the x where F(x) = p. The median is the 0.5 quantile, and the 90th percentile is the 0.9 quantile.

Key formulas

From density to probability

P(a ≤ X ≤ b) = ∫ab f(x) dx = F(b) − F(a)

f(x)
probability density function, f(x) ≥ 0 and total area 1

CDF and PDF are linked by calculus

F(x) = ∫−∞x f(t) dt,   f(x) = F′(x)

Mean, variance and quantiles

E[X] = ∫ x f(x) dx,   Var(X) = ∫ (x − E[X])² f(x) dx,   xp = F⁻¹(p)

x_p
the p-quantile; x_0.5 is the median

The distributions in the visualizer

DistributionSupportMeanVarianceMedian
Uniform(a, b)[a, b](a + b) / 2(b − a)² / 12(a + b) / 2
Exponential(λ)[0, ∞)1 / λ1 / λ²ln 2 / λ
Normal(μ, σ)(−∞, ∞)μσ²μ
Beta(α, β)[0, 1]α / (α + β)αβ / ((α + β)²(α + β + 1))no closed form
Gamma(k, θ)[0, ∞)kθkθ²no closed form

How to use this visualizer

  1. 1
    Pick a distribution and move its parameter sliders. Both charts and the summary (mean, median, variance) update together.
  2. 2
    Choose which probability to show: P(X ≤ a), P(a ≤ X ≤ b) or P(X ≥ a).
  3. 3
    Drag on either chart to move the nearest marker. The shaded area on the PDF and the highlighted bar on the CDF axis always show the same probability.
  4. 4
    Compare the density f(a) with the probabilities. Squeeze a normal to σ = 0.3 or a beta to α = β = 10 and the density rises well above 1, while every probability stays between 0 and 1.
  5. 5
    Type a probability p into the quantile box to find the x with F(x) = p (the purple point on the CDF), then press Move a to this quantile to check that the area to its left is p.

Common misconception

The height of a PDF is not a probability. A Uniform(0, 0.5) density equals 2 everywhere on its support, and a Beta(0.5, 0.5) density is infinite at both ends, yet both have total area exactly 1. To get a probability you always need a width: an area under the PDF, or a difference of two CDF values.

Practice problems

Problem 1: Waiting for a bus

The time X (in minutes) until the next bus is exponential with mean 2 minutes. Find P(1 ≤ X ≤ 3), the median wait, and the 90th percentile of the wait.
Show solution

Mean 1/λ = 2, so λ = 0.5 and F(x) = 1 − e^(−0.5x)

P(1 ≤ X ≤ 3) = F(3) − F(1) = e^(−0.5) − e^(−1.5) = 0.60653 − 0.22313 = 0.38340

Median: 1 − e^(−0.5m) = 0.5, so m = ln 2 / 0.5 ≈ 1.386 minutes

90th percentile: 1 − e^(−0.5x) = 0.9, so x = −ln(0.1) / 0.5 = 2 ln 10 ≈ 4.605 minutes

P ≈ 0.383, median ≈ 1.39 min, 90th percentile ≈ 4.61 min

Problem 2: A beta density

X has density f(x) = 6x(1 − x) on [0, 1], which is Beta(2, 2). Find the CDF, P(X ≤ 0.25), P(0.25 ≤ X ≤ 0.75), the mean and the variance. What is the largest value of f?
Show solution

F(x) = ∫₀ˣ 6t(1 − t) dt = 3x² − 2x³ for 0 ≤ x ≤ 1

P(X ≤ 0.25) = 3(0.0625) − 2(0.015625) = 0.1875 − 0.03125 = 0.15625

By symmetry F(0.75) = 1 − 0.15625 = 0.84375

P(0.25 ≤ X ≤ 0.75) = 0.84375 − 0.15625 = 0.6875

Mean = α/(α + β) = 2/4 = 0.5

Variance = αβ/((α + β)²(α + β + 1)) = 4/(16 × 5) = 0.05

Largest density: f(0.5) = 6 × 0.5 × 0.5 = 1.5, which is more than 1

F(x) = 3x² − 2x³; 0.15625; 0.6875; mean 0.5; variance 0.05; max f = 1.5

Related topics

Discussion

Questions, ideas or a different approach? Join the conversation.