Skip to content
svglorenz-gini

Lorenz curve and Gini

How unevenly is the total lifetime shared out among units?

Demo data · seed 20261101 · 60 rows · default settings · 640 × 360SVG, lightSVG, darkDemo CSV

How to read it

  1. Read x as the share of units, shortest-lived first, and y as their share of all the lifetime in the sample.
  2. Compare the curve with the dashed exponential curve, whose Gini is one half.
  3. Further below it means lifetimes are more unequal, which points to a falling failure rate; above it, a rising one.
  1. Callout 1: The line of equality: every unit lasts equally long.
  2. Callout 2: The exponential reference, Gini one half.
  3. Callout 3: The sample's curve, and the Gini is twice the area between it and equality.

Watch out

  • It compares lifetimes with each other, so it ignores the time scale. Two samples with very different mean lives can share a curve.

Defaults

Exponential reference
On
Show the Lorenz curve of an exponential distribution.

Pinned in the code

  • Curve: (i/n, Σ_{j≤i} x_(j) / Σ x). Gini: ΣΣ|x_i − x_j| / (2n(n−1)x̄), the finite-sample normalization of the guide's entry 145.
  • The exponential reference is L(p) = p + (1 − p) log(1 − p).
# Lorenz curve and Gini — Codesplash Chart Lab (recipe "lorenz-gini")
# controls: reference=true
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

try:
    import codesplash as cs  # optional: the app's chart theme
except ImportError:
    cs = None
if cs:
    cs.use_codesplash(dark=False)
PALETTE = cs.palette(dark=False)["categorical"] if cs else plt.rcParams["axes.prop_cycle"].by_key()["color"]

df = pd.read_csv("lorenz-gini-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV

_tokens = cs.palette(dark=False) if cs else {}
SEQ = _tokens.get("sequential", ["#eff6fd", "#1a469d"])  # sequential ramp (low → high)
DIV = _tokens.get("diverging", ["#c13e2e", "#f3f5f8", "#0859ac"])  # negative, midpoint, positive
REF = _tokens.get("reference", "#4e5661")
GREY = _tokens.get("dim", "#ced1d6")
V = "hours"
x = np.sort(df[V].dropna().to_numpy(dtype=float))
n = x.size
p_ = np.concatenate(([0.0], np.arange(1, n + 1) / n))
l_ = np.concatenate(([0.0], np.cumsum(x) / x.sum()))
gini = 2 * np.sum((2 * np.arange(1, n + 1) - n - 1) * x) / (2 * n * (n - 1) * x.mean())
grid = np.linspace(0, 0.999, 60)
ref = grid + (1 - grid) * np.log1p(-grid)  # exponential Lorenz curve
fig, ax = plt.subplots(figsize=(6, 5))
ax.plot([0, 1], [0, 1], color=GREY, label="equality")
ax.plot(grid, ref, color=REF, linestyle="--", label="exponential (Gini = 0.5)")
ax.plot(p_, l_, color=PALETTE[0], linewidth=1.8, label="Lorenz curve")
ax.set_xlabel("Share of units, shortest-lived first")
ax.set_ylabel("Share of total lifetime")
ax.set_title(f"Lorenz curve: Gini {gini:.3f}", fontsize=10, loc="left")
ax.legend(frameon=False)
plt.show()

Needs pandas, numpy, matplotlib · reads lorenz-gini-demo.csv · app theme from the optional codesplash helper