67 statistical charts · 13 families · 100% Python
Social data science.
Beautifully Pythonic.
Statistical charts for Python, set in real research questions from the social sciences and organised by the question they answer. Machine learning — how well a model predicts and why — and spatial data — maps and spatial autocorrelation — sit alongside distributions, group comparisons, regression and survival, and every figure reports the statistics behind it: estimates, confidence intervals, tests, effect sizes.
Most Python resources teach the code first and leave the questions for later. This gallery works the other way round. It was first written for social-science students, and it serves anyone who knows their field and has a question to answer — do these groups differ, do these two variables move together, why did the model predict this? Start from the question, find the chart that answers it, read the statistics it reports, and take only the code you need.
No chart matches your search. Try “regression”, “survey”, “confidence interval” or an R function name.
Machine learning
How well does a model predict on new data, and why? Out-of-fold evaluation, learning curves and model-agnostic explanations — each with its uncertainty.
Confusion matrix with metrics
How well a classifier sorts tweets into Environmental, Social and Governance topics — out-of-fold 3 × 3 confusion matrix with bootstrap intervals for the metrics.
yardstick::conf_mat() + autoplot()Precision–recall curves
Out-of-fold precision–recall curves for two classifiers predicting which Facebook users share COVID-19 fake news, with average precision and the no-skill baseline.
yardstick::pr_curve() + autoplot()Learning curve
Training and cross-validated accuracy as the training set grows, for two models predicting which Facebook users share COVID-19 fake news.
caret::learning_curve_dat() + ggplot()Cross-validated model comparison
Fold-by-fold R² of six models predicting the waste rate of production batches, with means and corrected 95% intervals.
caret::resamples() + bwplot() / tune::autoplot()Permutation importance
Which process features a random forest relies on to predict a batch's waste rate — drop in test-set R² when each one is shuffled.
vip::vip(method = "permute")Partial dependence with ICE curves
How a batch's predicted waste rate changes with machine speed and with days since maintenance — the average (PDP) over one curve per batch (ICE).
pdp::partial(ice = TRUE) + autoplot() / iml::FeatureEffectAdvanced: SHAP explanations
Shapley values split every prediction into additive feature contributions — globally, feature by feature, and for a single case.
SHAP summary (beeswarm)
Every production batch's SHAP value for every process feature, coloured by the feature's value, with mean |SHAP| importance.
shapviz::sv_importance(kind = "beeswarm")SHAP dependence plot
How days since maintenance feed into each batch's predicted waste rate, coloured by its strongest interaction partner, with a smooth trend.
shapviz::sv_dependence()SHAP waterfall for one prediction
How each process feature moves one high-waste batch's predicted waste rate from the average to the model's output.
shapviz::sv_waterfall()Spatial data
Is a value higher where its neighbours' values are higher? Spatial weights, global and local spatial autocorrelation, and how far clusters reach — along a schematic Great Lakes–St. Lawrence corridor.
Choropleth with spatial weights
A map of one variable with the neighbour network drawn on top — the structure every spatial statistic relies on.
spdep::poly2nb() + plot(nb, coords)Moran scatterplot (global autocorrelation)
Each area against the average of its neighbours, with Moran's I, its permutation test and the reference distribution.
spdep::moran.plot() + spdep::moran.mc()LISA cluster map (local autocorrelation)
Where the clusters and spatial outliers are — local Moran's I for each area, mapped with its permutation significance.
spdep::localmoran_perm() / rgeoda::local_moran()Spatial correlogram
Moran's I at increasing neighbour orders, with a permutation envelope — how far spatial clustering reaches.
spdep::sp.correlogram(method = "I")Distributions
See the shape of your data: histograms, densities, ridgelines, ECDFs and Q–Q plots.
Histogram with density
Histogram, kernel density and fitted normal curve, with shape statistics.
ggplot2::geom_histogram() + geom_density()Raincloud plot
Half violin, box plot and raw points per group, drawn horizontally.
ggdist::stat_halfeye() / ggrain::geom_rain()Ridgeline plot
Overlapping density curves to compare one distribution across many groups.
ggridges::geom_density_ridges()ECDF comparison
Empirical cumulative distributions of two groups, with the Kolmogorov–Smirnov gap.
ggplot2::stat_ecdf()Q–Q plot with confidence band
Normal quantile–quantile plots with a 95% envelope, for a raw and a logged variable.
qqplotr::stat_qq_band()Group comparisons
Compare groups with the test, effect size and p-values on the chart — the ggstatsplot way.
Between-groups comparison
Violin + box + points with Welch's ANOVA, effect size and pairwise tests.
ggstatsplot::ggbetweenstats()Within-subjects comparison
Repeated measures with one line per subject, means, rm-ANOVA and paired tests.
ggstatsplot::ggwithinstats()Estimation plot
Raw data of two groups plus the mean difference and its bootstrap 95% CI.
dabestr::dabest() + plot()Interaction plot
Group means with 95% confidence intervals for two factors, with a two-way ANOVA.
ggpubr::ggline(add = "mean_ci") / ggstatsTukey HSD intervals
Simultaneous 95% confidence intervals for every pairwise difference in means.
TukeyHSD() + plot()Proportions & surveys
Proportions, cross-tabs and Likert scales, in the spirit of ggstats::gglikert and stat_prop.
Diverging Likert chart
Five-point Likert items as diverging stacked bars centred on the neutral answer.
ggstats::gglikert()Stacked proportions by group
100% stacked bars with percentage labels, n per bar, chi-squared test and Cramér's V.
ggstatsplot::ggbarstats()Mosaic plot with Pearson residuals
Tile areas proportional to cell counts, shaded by Pearson residuals from independence.
vcd::mosaic(shade = TRUE)Proportions with confidence intervals
A sorted dot plot of proportions with Wilson 95% confidence intervals.
ggstats::stat_prop() + geom_errorbar()Cross-table with standardized residuals
A contingency table as a heatmap, coloured by standardized residuals from independence.
ggstats::ggtable() / stat_cross()Correlation & association
Correlation matrices, scatterplots with statistics and pairwise relationships.
Correlation matrix
Lower-triangle Pearson correlation heatmap; non-significant cells (Holm) are crossed out.
ggstatsplot::ggcorrmat()Scatterplot with statistics
Trade intensity vs business-cycle correlation for country pairs — scatter, OLS line with 95% band, marginal histograms and Pearson's r.
ggstatsplot::ggscatterstats()Pairs plot with correlations
Scatter matrix of four regional growth variables, with group KDEs on the diagonal and pooled vs within-group correlations above it.
GGally::ggpairs()Correlogram with clustering
Corrplot-style circles sized and coloured by r for 12 development indicators, ordered by hierarchical clustering.
corrplot::corrplot(order = "hclust", addrect = 3)Regression models
Coefficient plots, odds ratios, model comparison and marginal effects — ggcoef_model for Python.
Coefficient plot
Regression estimates with 95% confidence intervals, one row per term.
ggstats::ggcoef_model()Odds-ratio forest plot
Logistic regression odds ratios on a log scale, with a table of OR [95% CI] alongside.
ggstats::ggcoef_model(exponentiate = TRUE)Comparing nested models
Coefficients of three nested FDI regressions side by side, to see how estimates shift as an EU block is added.
ggstats::ggcoef_compare()Predicted probabilities
Model-based probability curves with 95% CI ribbons across a predictor, by group.
ggeffects::ggpredict() / marginaleffects::plot_predictions()Interaction effects
Simple slopes at mean ± 1 SD and a Johnson–Neyman plot for capital inflows and credit growth, moderated by exchange-rate flexibility.
interactions::interact_plot() / interactions::johnson_neyman()Quantile regression process
How a slope changes across the conditional distribution, against the single OLS estimate.
quantreg::plot(summary(rq(tau = 1:19 / 20)))Model diagnostics
Residuals, leverage, calibration and ROC curves: check before you trust a model.
Residual diagnostics
The classic 2 × 2 panel for a linear model — linearity, normality, variance, leverage.
plot(lm) / performance::check_model()Influence plot
Studentized residuals vs leverage, with bubbles sized by Cook's distance.
car::influencePlot()ROC curves
Three classifiers compared by ROC curve, AUC with bootstrap 95% CI and Youden point.
pROC::ggroc() / pROC::ci.auc()Calibration plot
Predicted vs observed risk per decile, with Wilson CIs, prediction histograms and Brier score.
rms::calibrate() / probably::cal_plot_breaks()Added-variable plots
One partial-regression panel per predictor; each fitted slope equals its coefficient.
car::avPlots()Survival analysis
Kaplan–Meier curves with risk tables, cumulative hazards and Cox model hazard ratios.
Kaplan–Meier curves
Time from patent filing to grant, domestic vs foreign applicants, with log-rank test and risk table.
survminer::ggsurvplot(risk.table = TRUE)Cox hazard ratios
Forest plot of a Cox model of time to patent grant, with HR, 95% CI and p-values.
survminer::ggforest()Cumulative hazard
Nelson–Aalen cumulative hazard of a drug's launch, with 95% bands, in four market groups.
survminer::ggsurvplot(fun = "cumhaz")Adjusted survival curves
Cox-predicted time to patent grant at four levels of relatedness, other covariates at their mean.
survminer::ggadjustedcurves()Time series
Decomposition, autocorrelation, forecasts with prediction intervals and change over time.
STL decomposition
Monthly manufacturing sales split into trend, seasonal and remainder components.
feasts::STL() + autoplot()ACF and PACF
ACF and PACF of a monthly sovereign bond spread over the Bund, with 95% significance bands.
forecast::ggtsdisplay()SARIMA forecast
Seasonal ARIMA forecast of monthly manufacturing sales, with 80% and 95% intervals vs held-out data.
forecast::autoplot(forecast())Seasonal subseries plot
Each calendar month's manufacturing sales across the years, with the monthly mean.
feasts::gg_subseries()Multivariate & clustering
PCA biplots, scree plots, clustering and heatmaps for high-dimensional data.
PCA biplot
European countries on institutional and economic indicators, Western Balkans highlighted.
factoextra::fviz_pca_biplot()Scree plot
How many dimensions describe digital skills in 300 occupations? Variance per component and a parallel-analysis cut-off.
factoextra::fviz_eig()Silhouette plot for k-means
Do industries fall into clusters of growth co-movement? k-means clusters next to their silhouette widths.
factoextra::fviz_silhouette()Clustered heatmap
Jaccard similarity between 24 party manifestos, with dendrograms and party-family colour bars.
pheatmap::pheatmap() / ComplexHeatmap::Heatmap()Inference & uncertainty
Bootstrap, confidence intervals, power, agreement and meta-analysis forest plots.
Bootstrap distribution
Online sellers and price dispersion across 20 products — resampled correlation with percentile and BCa 95% CIs.
boot::boot() + boot::boot.ci()What a 95% confidence interval means
100 surveys of 30 firms out of 2,000; the 95% CIs for the mean climate-risk score that miss are in red.
teaching classic (e.g. TeachingDemos::ci.examp())Power curve
Power of a two-sample t-test against sample size for small, medium and large effects.
pwr::pwr.t.test() + plot()Bland–Altman plot
Do AI-assisted and expert scores of IPCC scenario passages agree? Bias and 95% limits of agreement.
BlandAltmanLeh::bland.altman.plot() / blandr::blandr.draw()Meta-analysis forest plot
Do teacher expectations raise pupils' IQ? 19 "Pygmalion" experiments, a random-effects pooled diamond and heterogeneity statistics.
meta::forest() / metafor::forest()Funnel plot
Are small "Pygmalion" studies more optimistic? 19 teacher-expectancy effects against their standard error, with a pseudo 95% funnel and Egger's test.
metafor::funnel() + metafor::regtest()Academic tables
Publication-ready tables — regression tables, summary statistics and model results typeset like a journal page, with Great Tables. stargazer for Python.
Regression table, stargazer style
Three nested OLS models side by side, with standard errors under the coefficients and fit statistics at the foot, typeset like a journal table.
stargazer::stargazer(type = "html")Summary statistics table
The "Table 1" of an empirical paper — N, mean, SD, min, median and max per variable in panels, with group means and a test of their difference.
modelsummary::datasummary_balance()Machine learning model comparison table
Five classifiers compared on repeated cross-validation — discrimination, classification and calibration metrics as mean (SD), best in bold, with corrected tests of the AUC gap.
tidymodels::workflow_map() + collect_metrics()Panel data regression table
Pooled OLS, random effects, country fixed effects and two-way fixed effects side by side, with clustered standard errors, fixed-effect indicators and a Hausman test.
fixest::etable()Difference-in-differences table
Staggered adoption estimated four ways — two-way fixed effects, with controls, Gardner's two-stage DiD and Wooldridge's extended TWFE — with a pre-trend test and the true effect for comparison.
fixest::etable() + did2s::did2s() + etwfe::etwfe()Instrumental variables table
OLS against 2SLS, LIML and GMM, with the second stage and the first stage in two panels and the usual diagnostics — first-stage F, partial R², endogeneity and overidentification tests.
fixest::etable() + ivreg::ivreg()How to cite
PyStatlas is created and maintained by Thierry Warin. If it helped your work, please cite it.
Warin, T. (2026). PyStatlas: A Python Gallery of Statistical Graphics for the Social Sciences (Version 1.1.0) [Computer software]. https://warin.ca/pystatlas/
@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}
}