レインクラウドプロット
群ごとに半分のバイオリン、箱ひげ図、個々のデータ点を横向きに描きます。

レインクラウドプロットは、同じデータに対する3つの見方を重ねたものです。半分のバイオリン(「雲」)が密度を、細い箱ひげ図が中央値と四分位数を示し、その下にジッターをかけて並べた点(「雨」)がすべての観測値を表します。何も隠されないため、二峰性、外れ値、小標本のいずれも一目でわかります。
データは、lifelines に同梱されている Democracy and Dictatorship データ(lifelines.datasets.load_dd())から取った、1946年から2008年までの3種類の体制における政府首脳の在任期間のうち、終了した964件です。データの終了時点でまだ在任中の指導者(打ち切りのある在任期間)は除いています。密度は scipy.stats.gaussian_kde で求め、サブタイトルには、偏った分布をもつ期間データに適した順位検定であるクラスカル・ウォリス検定(scipy.stats.kruskal)の結果を効果量 ε² とともに示しています。
コードおよび図中のテキストは英語です。
import matplotlib.pyplot as plt
import numpy as np
from lifelines.datasets import load_dd
from scipy import stats
# Data: years in office of leaders whose spell ended, by regime type
df = load_dd().query("observed == 1")
groups = {"Parliamentary Dem": "Parliamentary democracy",
"Presidential Dem": "Presidential democracy", "Military Dict": "Military dictatorship"}
data = [df.loc[df.regime == g, "duration"].to_numpy() for g in groups]
palette = ["#007AFF", "#FF9500", "#34C759"]
# Kruskal–Wallis test + epsilon squared
H, p = stats.kruskal(*data)
n = sum(len(d) for d in data)
eps2 = H / (n - 1)
fig, ax = plt.subplots(figsize=(8, 5.2))
rng = np.random.default_rng(7)
for i, (d, c) in enumerate(zip(data, palette)):
# Cloud: half violin above the baseline, scaled to a fixed height
grid = np.linspace(d.min() - 0.5, d.max() + 0.5, 300) # trim the cloud near the data
dens = stats.gaussian_kde(d)(grid)
ax.fill_between(grid, i, i + 0.55 * dens / dens.max(), color=c, alpha=0.3, lw=0)
ax.plot(grid, i + 0.55 * dens / dens.max(), color=c, lw=1.4)
# Box: median and quartiles just under the cloud
ax.boxplot(d, positions=[i - 0.1], widths=0.09, vert=False, showfliers=False,
patch_artist=True, boxprops=dict(facecolor="white", edgecolor="#3A3A3C", lw=1),
medianprops=dict(color=c, lw=2.2), whiskerprops=dict(color="#3A3A3C"),
capprops=dict(visible=False))
# Rain: jittered raw points below the box
ax.scatter(d, i - 0.3 + rng.uniform(-0.08, 0.08, len(d)),
s=12, color=c, alpha=0.55, lw=0)
ax.set_yticks(range(len(groups)), [f"{g}\nmedian {np.median(d):.0f} yrs · n = {len(d)}"
for g, d in zip(groups.values(), data)])
ax.set_ylim(-0.5, len(groups) - 0.3)
ax.set_xlim(0, 36)
ax.grid(axis="x"); ax.grid(axis="y", visible=False)
ax.set_xlabel("Years in office")
share = [np.mean(d > 10) for d in data]
ax.set_title(f"{share[2]:.0%} of military rulers stay over 10 years, "
f"{share[1]:.1%} of presidents", pad=26)
ax.text(0, 1.02, f"Kruskal–Wallis H(2) = {H:.1f}, p = {p:.3f}, ε² = {eps2:.2f} · "
"cloud = density, box = quartiles, rain = leaders", transform=ax.transAxes,
fontsize=9.5, color="#6E6E73")
plt.show()
図にはオプションの PyStatlas スタイル を使用しています。同じ見た目にするには plt.style.use("pystatlas.mplstyle") を追加してください。
データの出典
- Democracy and Dictatorship: leader spells, 1946–2008. Cheibub, J. A., Gandhi, J., & Vreeland, J. R. (2010). Democracy and dictatorship revisited. Public Choice, 143(1–2), 67–101. https://doi.org/10.1007/s11127-009-9491-2
202 countries; distributed with lifelines (lifelines.datasets.load_dd).
これらの例は統計手法を説明するためのものです。図のタイトルは、この特定のデータ(多くは小規模で、古く、部分的な標本)で図が示す内容を述べたものであり、実質的な問いに対する著者の立場ではありません。解釈、背景、データの質については、ここに挙げた元の出典を参照してください。
引用方法
PyStatlas は Thierry Warin が作成・運営しています。研究や業務に役立った場合は、ぜひ引用してください。
Warin, T. (2026). Raincloud plot. In PyStatlas: A Python Gallery of Statistical Graphics for the Social Sciences. https://warint.github.io/pystatlas/distributions/raincloud/
@misc{warin2026statlas,
author = {Warin, Thierry},
title = {PyStatlas: A Python Gallery of Statistical Graphics for the Social Sciences},
year = {2026},
howpublished = {\url{https://warint.github.io/pystatlas/}},
note = {Source code: https://github.com/warint/pystatlas}
}