About PyStatlas
Statistical charts for Python, built on real social-science data 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.
PyStatlas starts from the questions researchers ask, not from the code. It was first written for social-science students who know their field and need to answer a question with data: do these groups differ, do two variables move together, what does the model predict and why? Each chart puts the relevant statistics on the figure and comes with a short, self-contained script built on the scientific Python stack — in the spirit of ggstats and ggstatsplot in R.
Principles
- Self‑contained. Every script runs as is. Data are real social‑science datasets bundled with statsmodels and lifelines (elections, schools, crime, fertility, regimes, recidivism…), a small published table typed in, or — rarely — a labelled, seeded simulation. The spatial examples fetch Guerry's map of France once through libpysal, then use the cached copy.
- Statistics first. Each chart carries the numbers that matter: estimates, intervals, test statistics, effect sizes.
- Folder = page. The repository tree mirrors the site. Every example lives in
gallery/<family>/<chart>/plot.pywith a renderedplot.pngand README.
Families
| Family | Charts | What you'll find |
|---|---|---|
| Machine learning | 9 | 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. |
| Spatial data | 4 | Is a value higher where its neighbours' values are higher? Spatial weights, global and local spatial autocorrelation, and how far clusters reach — on Guerry's 1830s France. |
| Distributions | 5 | See the shape of your data: histograms, densities, ridgelines, ECDFs and Q–Q plots. |
| Group comparisons | 5 | Compare groups with the test, effect size and p-values on the chart — the ggstatsplot way. |
| Proportions & surveys | 5 | Proportions, cross-tabs and Likert scales, in the spirit of ggstats::gglikert and stat_prop. |
| Correlation & association | 4 | Correlation matrices, scatterplots with statistics and pairwise relationships. |
| Regression models | 6 | Coefficient plots, odds ratios, model comparison and marginal effects — ggcoef_model for Python. |
| Model diagnostics | 5 | Residuals, leverage, calibration and ROC curves: check before you trust a model. |
| Survival analysis | 4 | Kaplan–Meier curves with risk tables, cumulative hazards and Cox model hazard ratios. |
| Time series | 4 | Decomposition, autocorrelation, forecasts with prediction intervals and change over time. |
| Multivariate & clustering | 4 | PCA biplots, scree plots, clustering and heatmaps for high-dimensional data. |
| Inference & uncertainty | 6 | Bootstrap, confidence intervals, power, agreement and meta-analysis forest plots. |
Author
PyStatlas is created and maintained by Thierry Warin. More of his work on data science, statistics and AI: www.warin.ca.
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. https://warint.github.io/pystatlas/
@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}
}Contribute
Add a folder with a plot.py, run python build.py, open a pull request. See CONTRIBUTING.md.
Thank you
PyStatlas stands on the shoulders of open-source software, open data and the R community. Every example is built with, or inspired by, the work below.
Python packages used in the examples
NumPy · pandas · Matplotlib · seaborn · SciPy · statsmodels · scikit-learn · lifelines · SHAP · GeoPandas · libpysal · esda
Datasets
Inspiration
- The R Graph Gallery (Yan Holtz)
- ggstatsplot (Indrajeet Patil) —
ggbetweenstats(),ggwithinstats(),ggbarstats(),ggcorrmat(),ggscatterstats() - ggstats (Joseph Larmarange) —
gglikert(),stat_prop(),ggtable(),ggcoef_model(),ggcoef_compare() - ggdist (Matthew Kay) and ggrain (Nicholas Judd, Jordy van Langen) —
stat_halfeye(),geom_rain() - ggridges (Claus O. Wilke) —
geom_density_ridges() - survminer and factoextra (Alboukadel Kassambara) —
ggsurvplot(),ggforest(),ggadjustedcurves(),fviz_pca_biplot(),fviz_eig(),fviz_silhouette() - dabestr (Joses W. Ho and colleagues) —
dabest() - performance, easystats (Daniel Lüdecke and colleagues) —
check_model() - metafor (Wolfgang Viechtbauer) —
forest(),funnel(),regtest() - GGally (Barret Schloerke, Di Cook) —
ggpairs() - corrplot (Taiyun Wei, Viliam Simko) —
corrplot() - SHAP (Scott Lundberg and Su-In Lee, 2017) and shapviz (Michael Mayer) —
sv_importance(),sv_dependence(),sv_waterfall() - spdep (Roger Bivand) and GeoDa / rgeoda (Luc Anselin, Xun Li) —
poly2nb(),moran.plot(),moran.mc(),localmoran_perm(),sp.correlogram(),local_moran() - vip and pdp (Brandon Greenwell, Bradley Boehmke) and tidymodels' yardstick —
vip(),partial(),conf_mat(),pr_curve()
R packages whose charts the examples mirror
BlandAltmanLeh · blandr · boot · car · caret · ComplexHeatmap · corrplot · dabestr · factoextra · feasts · forecast · GGally · ggdist · ggeffects · ggplot2 · ggpubr · ggrain · ggridges · ggstats · ggstatsplot · iml · interactions · marginaleffects · meta · metafor · pdp · performance · pheatmap · probably · pROC · pwr · qqplotr · quantreg · rgeoda · rms · shapviz · spdep · survminer · TeachingDemos · tune · vcd · vip · yardstick
Building the site
PyYAML · Pygments · Pillow · GitHub Pages
Data sources
Almost every example uses published data, reproduced as distributed with statsmodels, lifelines or R's metafor; the two simulated examples are marked as such. Each entry gives the original reference, how the data reach the gallery, and the charts that use them.
- American National Election Study, 1996. Rosenstone, S. J., Kinder, D. R., Miller, W. E., & the National Election Studies. (2016). ANES 1996 Time Series Study (ICPSR 6896; Version 6) [Data set]. Inter-university Consortium for Political and Social Research. https://doi.org/10.3886/ICPSR06896.v6
Subset of 944 respondents distributed with statsmodels (sm.datasets.anes96); public domain.
Used in: Confusion matrix with metrics, Interaction plot, Tukey HSD intervals, Stacked proportions by group, What a 95% confidence interval means - California STAR test results, 1998 (303 school districts). Gill, J. (2001). Generalized Linear Models: A Unified Approach (Quantitative Applications in the Social Sciences, No. 134). Sage. https://www.statsmodels.org/stable/datasets/generated/star98.html
Original data from the California Department of Education's Standardized Testing and Reporting (STAR) program, 1998. Subset distributed with statsmodels (sm.datasets.star98) with the author's permission.
Used in: Cross-validated model comparison, Permutation importance, Partial dependence with ICE curves, SHAP summary (beeswarm), SHAP dependence plot, SHAP waterfall for one prediction, Between-groups comparison, Scatterplot with statistics, Pairs plot with correlations, Correlogram with clustering, Comparing nested models, Interaction effects, Scree plot - US state crime and social indicators, 2009. U.S. Census Bureau. Statistical Abstract of the United States, state tables for 2009 (crime rates from the FBI Uniform Crime Reporting program). https://www.statsmodels.org/stable/datasets/generated/statecrime.html
Compiled for statsmodels (sm.datasets.statecrime); public domain. See the statsmodels page for each variable's table and footnotes.
Used in: Estimation plot, Correlation matrix, Coefficient plot, Residual diagnostics, Influence plot, Added-variable plots, PCA biplot, Silhouette plot for k-means, Clustered heatmap, Bootstrap distribution - Redbook survey of married women, 1974 (Fair's affairs data). Fair, R. C. (1978). A theory of extramarital affairs. Journal of Political Economy, 86(1), 45–61. https://doi.org/10.1086/260646
Data from the 1974 Redbook magazine survey; distributed with statsmodels (sm.datasets.fair) with the author's permission.
Used in: Precision–recall curves, Learning curve, Mosaic plot with Pearson residuals, Proportions with confidence intervals, Cross-table with standardized residuals, Odds-ratio forest plot, ROC curves, Calibration plot - World Bank fertility rates by country, 1960–2013. World Bank. Fertility rate, total (births per woman), indicator SP.DYN.TFRT.IN. World Development Indicators. https://data.worldbank.org/indicator/SP.DYN.TFRT.IN
Primary sources: UN Population Division, UN Statistical Division, national statistical offices, Eurostat and others. Distributed with statsmodels (sm.datasets.fertility) under the World Bank terms of use.
Used in: Histogram with density, Ridgeline plot, Within-subjects comparison - Engel's Belgian household budgets (235 families). Koenker, R., & Bassett, G. (1982). Robust tests for heteroscedasticity based on regression quantiles. Econometrica, 50(1), 43–61. https://doi.org/10.2307/1912528
Engel's (1857) household budget data as used by Koenker and Bassett and distributed with R's quantreg; in statsmodels as sm.datasets.engel; public domain.
Used in: Q–Q plot with confidence band, Quantile regression process - Spector and Mazzeo's teaching-method experiment (32 students). Spector, L. C., & Mazzeo, M. (1980). Probit analysis and economic education. Journal of Economic Education, 11(2), 37–44. https://www.statsmodels.org/stable/datasets/generated/spector.html
Obtained from W. Greene's Econometric Analysis web site with the original author's permission; distributed with statsmodels (sm.datasets.spector).
Used in: Predicted probabilities - US quarterly macroeconomic series, 1959–2009. Federal Reserve Bank of St. Louis. FRED, Federal Reserve Economic Data; U.S. Bureau of Labor Statistics (unemployment rate). Accessed December 15, 2009. https://fred.stlouisfed.org/
Compiled by Skipper Seabold for statsmodels (sm.datasets.macrodata); public domain.
Used in: ACF and PACF - Euro-area electrical-equipment turnover, monthly, 1995–2016. Eurostat. Euro area (18, fixed composition) total turnover index, manufacture of electrical equipment (NACE Rev. 2), working-day adjusted, not seasonally adjusted. https://ec.europa.eu/eurostat
Distributed with statsmodels (statsmodels.datasets.elec_equip); public domain.
Used in: STL decomposition, SARIMA forecast, Seasonal subseries plot - 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).
Used in: Raincloud plot, Kaplan–Meier curves, Cumulative hazard - Rossi recidivism experiment (432 released prisoners). Rossi, P. H., Berk, R. A., & Lenihan, K. J. (1980). Money, Work, and Crime: Some Experimental Results. Academic Press. https://lifelines.readthedocs.io/en/latest/lifelines.datasets.html
Men released from Maryland state prisons in the 1970s, half randomly assigned to financial aid. Distributed with lifelines (lifelines.datasets.load_rossi).
Used in: ECDF comparison, Cox hazard ratios, Adjusted survival curves - Teacher-expectancy experiments (Raudenbush, 1984). Raudenbush, S. W. (1984). Magnitude of teacher expectancy effects on pupil IQ as a function of the credibility of expectancy induction: A synthesis of findings from 18 experiments. Journal of Educational Psychology, 76(1), 85–97. https://doi.org/10.1037/0022-0663.76.1.85
Effect sizes and variances typed in from dat.raudenbush1985 in R's metadat/metafor (Viechtbauer, 2010, Journal of Statistical Software, 36(3), https://doi.org/10.18637/jss.v036.i03); one of the 18 experiments contributes two rows.
Used in: Meta-analysis forest plot, Funnel plot - 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.
Used in: Diverging Likert chart, Bland–Altman plot - Guerry's moral statistics of France, c. 1830 (85 départements). Guerry, A.-M. (1833). Essai sur la statistique morale de la France. Crochard. Data as compiled in Friendly, M. (2007). A.-M. Guerry's moral statistics of France: Challenges for multivariable spatial analysis. Statistical Science, 22(3), 368–399. https://doi.org/10.1214/07-STS241
Prepared by the Center for Spatial Data Science (University of Chicago) from the R package Guerry (Friendly and Dray), provided “as is”. Fetched once and cached by libpysal (examples.load_example("Guerry")). Variables come from Guerry's tables as translated by Whitt and Reinking (2002).
Used in: Choropleth with spatial weights, Moran scatterplot (global autocorrelation), LISA cluster map (local autocorrelation), Spatial correlogram
The examples illustrate statistical methods. Their titles describe what each figure shows in these particular data — often a small, dated or partial sample — not the author's position on the substantive question. For interpretation, context and data quality, rely on the original sources cited here.