Graphique en nuage de pluie
Demi-violon, boîte à moustaches et points bruts par groupe, tracés à l'horizontale.

Un graphique en nuage de pluie (raincloud plot) superpose trois vues des mêmes données : un demi-violon (le « nuage ») montre la densité, une fine boîte à moustaches donne la médiane et les quartiles, et les points dispersés en dessous (la « pluie ») montrent chaque observation. Rien n'est caché : l'asymétrie, les valeurs aberrantes et les petits échantillons sont tous visibles.
Le contexte est celui de de Marcellis-Warin, Kouloukoui et Warin (2025, Data in Brief), un vaste jeu de données de tweets portant sur l'intelligence artificielle. Les chiffres sont ici simulés à des fins d'illustration — un score de sentiment compris entre −1 (négatif) et +1 (positif) pour n = 480 tweets répartis entre quatre thèmes liés à l'IA — et ne sont ni les données ni les résultats de l'article. Les densités proviennent de scipy.stats.gaussian_kde, et le sous-titre rapporte un test de Kruskal–Wallis (scipy.stats.kruskal) — un test de rangs, adapté à des scores bornés et asymétriques — avec ε² comme taille d'effet.
Le code et le texte à l'intérieur des figures sont en anglais.
import matplotlib.pyplot as plt
import numpy as np
from scipy import stats
# Simulated data, set in the context of de Marcellis-Warin, Kouloukoui & Warin (2025) [dmw2025aitweets]
# Data: sentiment score (−1 to +1) of 120 tweets per AI topic (Beta draws rescaled)
rng = np.random.default_rng(2025)
groups = {"AI in healthcare": (5.0, 3.5), "Generative AI tools": (4.0, 3.5),
"AI regulation": (3.5, 4.0), "AI and jobs": (2.6, 4.5)}
data = [2 * rng.beta(a, b, 120) - 1 for a, b in groups.values()]
palette = ["#007AFF", "#FF9500", "#34C759", "#FF3B30"]
# 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.6))
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.05, d.max() + 0.05, 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, orientation="horizontal", 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):+.2f} · n = {len(d)}"
for g, d in zip(groups, data)])
ax.set_ylim(-0.5, len(groups) - 0.3)
ax.set_xlim(-1, 1)
ax.axvline(0, color="#8E8E93", lw=0.8, ls="--", zorder=0)
ax.grid(axis="x"); ax.grid(axis="y", visible=False)
ax.set_xlabel("Tweet sentiment score (−1 = negative, +1 = positive)")
share = [np.mean(d < 0) for d in data]
ax.set_title(f"{share[3]:.0%} of tweets on AI and jobs are negative, "
f"{share[0]:.0%} of those on AI in healthcare", pad=26)
ax.text(0, 1.02, f"n = {n} tweets (simulated) · Kruskal–Wallis H(3) = {H:.1f}, p = {p:.1e}, "
f"ε² = {eps2:.2f} · box = quartiles, rain = tweets", transform=ax.transAxes,
fontsize=9.5, color="#6E6E73")
plt.show()
# Raincloud plot: the R equivalent of plot.py
# Simulated data, set in the context of de Marcellis-Warin, Kouloukoui & Warin (2025) [dmw2025aitweets]
# R and NumPy draw different random numbers, so the values differ slightly from the Python figure.
library(ggplot2)
set.seed(2025)
# Data: sentiment score (-1 to +1) of 120 tweets per AI topic (Beta draws rescaled)
topics <- c("AI in healthcare", "Generative AI tools", "AI regulation", "AI and jobs")
shape1 <- c(5.0, 4.0, 3.5, 2.6)
shape2 <- c(3.5, 3.5, 4.0, 4.5)
palette <- setNames(c("#007AFF", "#FF9500", "#34C759", "#FF3B30"), topics)
d <- do.call(rbind, lapply(1:4, function(i)
data.frame(topic = topics[i], pos = i - 1, score = 2 * rbeta(120, shape1[i], shape2[i]) - 1)))
n <- nrow(d)
# Kruskal-Wallis test + epsilon squared
kw <- kruskal.test(score ~ topic, data = d)
H <- unname(kw$statistic)
eps2 <- H / (n - 1)
# Cloud: half violin above the baseline, trimmed near the data and scaled to a fixed height
cloud <- do.call(rbind, lapply(split(d, d$topic), function(g) {
k <- density(g$score, from = min(g$score) - 0.05, to = max(g$score) + 0.05, n = 300)
data.frame(topic = g$topic[1], pos = g$pos[1], score = k$x, height = 0.55 * k$y / max(k$y))
}))
# Rain: jittered raw points below the box
d$rain <- d$pos - 0.3 + runif(n, -0.08, 0.08)
# Group summaries: median for the box and the axis labels, share of negative tweets for the title
med <- aggregate(score ~ topic + pos, data = d, FUN = median)
med <- med[order(med$pos), ]
share <- tapply(d$score < 0, d$topic, mean)
p <- ggplot(d, aes(x = score, colour = topic, fill = topic)) +
geom_vline(xintercept = 0, colour = "#8E8E93", linewidth = 0.4, linetype = "dashed") +
geom_ribbon(data = cloud, aes(ymin = pos, ymax = pos + height), alpha = 0.3, linewidth = 0) +
geom_line(data = cloud, aes(y = pos + height), linewidth = 0.6) +
# Box: median and quartiles just under the cloud
geom_boxplot(aes(y = pos - 0.1, group = topic), orientation = "y", width = 0.09,
outlier.shape = NA, fill = "white", colour = "#3A3A3C", linewidth = 0.4,
fatten = 0) +
geom_segment(data = med, aes(xend = score, y = pos - 0.145, yend = pos - 0.055),
linewidth = 1, lineend = "butt") +
geom_point(aes(y = rain), size = 1, alpha = 0.55, stroke = 0) +
scale_colour_manual(values = palette, aesthetics = c("colour", "fill"), guide = "none") +
scale_x_continuous(limits = c(-1, 1), expand = c(0, 0)) +
scale_y_continuous(breaks = med$pos, limits = c(-0.5, 3.7), expand = c(0, 0),
labels = sprintf("%s\nmedian %+.2f · n = 120", med$topic, med$score)) +
labs(title = sprintf("%.0f%% of tweets on AI and jobs are negative, %.0f%% of those on AI in healthcare",
100 * share[["AI and jobs"]], 100 * share[["AI in healthcare"]]),
subtitle = sprintf(paste("n = %d tweets (simulated) · Kruskal–Wallis H(3) = %.1f, p = %.1e,",
"ε² = %.2f · box = quartiles, rain = tweets"),
n, H, kw$p.value, eps2),
x = "Tweet sentiment score (−1 = negative, +1 = positive)", y = NULL) +
theme_minimal(base_size = 11) +
theme(plot.title = element_text(face = "bold", size = 11.5),
plot.title.position = "plot",
plot.subtitle = element_text(size = 8.5, colour = "#6E6E73"),
axis.text.y = element_text(colour = "#1D1D1F", lineheight = 0.95),
panel.grid.minor = element_blank(), panel.grid.major.y = element_blank(),
plot.margin = margin(8, 14, 8, 8))
print(p)
Les figures utilisent le style PyStatlas (facultatif) : ajoutez plt.style.use("pystatlas.mplstyle") pour obtenir exactement le même rendu.
Source des données
- Simulated data. Simulated data with a fixed random seed, created for this example.
No real respondents, documents or measurements: the numbers only illustrate how the chart and its statistics work. - de Marcellis-Warin, Kouloukoui & Warin (2025), AI-related tweets. de Marcellis-Warin, N., Kouloukoui, D., & Warin, T. (2025). A large-scale dataset of AI-related tweets: Structure and descriptive statistics. Data in Brief, 62, 111960. https://doi.org/10.1016/j.dib.2025.111960
The example is set in the context of this paper; unless its description says otherwise, the numbers are simulated and are not the paper's data or results.
Les exemples illustrent des méthodes statistiques. Leurs chiffres sont simulés, sauf mention contraire dans l'entrée, et leurs titres décrivent ce que chaque figure montre dans ces données simulées — ni les résultats des articles cités, ni la position de l'auteur sur la question de fond. Pour les résultats, le contexte et les données, reportez-vous aux articles cités ici.
Comment citer
PyStatlas est créé et maintenu par Thierry Warin. S'il vous a été utile dans vos travaux, merci de le citer.
Warin, T. (2026). Raincloud plot. In PyStatlas: A Python Gallery of Statistical Graphics for the Social Sciences (Version 1.1.0) [Computer software]. https://warin.ca/pystatlas/distributions/raincloud/
@misc{warin2026statlas,
author = {Warin, Thierry},
title = {PyStatlas: A Python Gallery of Statistical Graphics for the Social Sciences},
year = {2026},
version = {1.1.0},
howpublished = {\url{https://warin.ca/pystatlas/}},
note = {Source code: https://github.com/warint/pystatlas}
}Plus dans Distributions
Histogramme avec densité
Histogramme, densité par noyau et courbe normale ajustée, avec statistiques de forme.
ggplot2::geom_histogram() + geom_density()Graphique en crêtes
Courbes de densité qui se chevauchent pour comparer une distribution entre de nombreux groupes.
ggridges::geom_density_ridges()Comparaison de fonctions de répartition empiriques
Fonctions de répartition empiriques de deux groupes, avec l'écart de Kolmogorov–Smirnov.
ggplot2::stat_ecdf()