关于 PyStatlas

以社会科学中的真实研究问题为背景、按所回答的问题组织的 Python 统计图表。机器学习(模型预测得多好、为什么这样预测)和空间数据(地图与空间自相关)与分布、组间比较、回归和生存分析并列收录;每张图都给出其背后的统计量——估计值、置信区间、检验和效应量。

PyStatlas 从研究者提出的问题出发,而不是从代码出发。它最初是为社会科学专业的学生编写的:他们熟悉自己的领域,需要用数据回答问题——这些组之间有差异吗?两个变量是否同步变化?模型预测了什么,为什么?每张图都把相关统计量标在图上,并附有一段基于 Python 科学计算生态、简短且自包含的脚本——与 R 中 ggstats 和 ggstatsplot 的理念一致。

设计原则

图表类别

类别图表内容概览
机器学习9模型对新数据的预测效果如何?原因何在?样本外评估、学习曲线与模型无关的解释——每一项都附带其不确定性。
空间数据4邻近地区的数值越高,某地的数值是否也越高?空间权重、全局与局部空间自相关,以及聚集的范围——基于示意性的五大湖–圣劳伦斯走廊。
分布5看清数据的形态:直方图、密度图、山脊图、ECDF 与 Q–Q 图。
组间比较5以 ggstatsplot 的方式比较各组,将检验、效应量和 p 值直接标注在图上。
比例与问卷调查5比例、交叉表与 Likert 量表,延续 ggstats::gglikert 与 stat_prop 的风格。
相关与关联4相关矩阵、附带统计量的散点图以及变量两两之间的关系。
回归模型6系数图、优势比、模型比较与边际效应——Python 版的 ggcoef_model。
模型诊断5残差、杠杆值、校准与 ROC 曲线:先检验,再信任模型。
生存分析4附风险表的 Kaplan–Meier 曲线、累积风险以及 Cox 模型风险比。
时间序列4序列分解、自相关、带预测区间的预测以及随时间的变化。
多元分析与聚类4面向高维数据的 PCA 双标图、碎石图、聚类与热图。
推断与不确定性6自助法(Bootstrap)、置信区间、统计功效、一致性分析与元分析森林图。
学术表格6可直接用于发表的表格——回归表、描述性统计和模型结果,用 Great Tables 排成期刊版式。Python 版的 stargazer。

作者

PyStatlas 由 Thierry Warin 创建并维护。更多关于数据科学、统计学与人工智能的作品,请访问:www.warin.ca。

如何引用

PyStatlas 由 Thierry Warin 创建并维护。如果它对你的工作有所帮助,敬请引用。

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}
}

参与贡献

新建一个包含 plot.py 的文件夹,运行 python build.py,然后提交 pull request。详见 CONTRIBUTING.md。

致谢

PyStatlas 建立在开源软件、开放数据和 R 社区的成果之上。每个示例都使用了以下工作,或受其启发。

示例中使用的 Python 包

NumPy · pandas · Matplotlib · seaborn · SciPy · statsmodels · scikit-learn · lifelines · SHAP · GeoPandas · libpysal · esda · Shapely · Great Tables · linearmodels · pyfixest

数据集

灵感来源

示例所对应的 R 包

BlandAltmanLeh · blandr · boot · car · caret · ComplexHeatmap · corrplot · dabestr · did2s · etwfe · factoextra · feasts · fixest · forecast · GGally · ggdist · ggeffects · ggplot2 · ggpubr · ggrain · ggridges · ggstats · ggstatsplot · iml · interactions · ivreg · marginaleffects · meta · metafor · modelsummary · pdp · performance · pheatmap · probably · pROC · pwr · qqplotr · quantreg · rgeoda · rms · shapviz · spdep · stargazer · survminer · TeachingDemos · tidymodels · tune · vcd · vip · yardstick

网站构建

PyYAML · Pygments · Pillow · GitHub Pages

研究与数据来源

几乎所有示例都以作者一篇已发表论文为背景(空间数据图表则以 CIRANO 的 GVCdtLab 为背景),使用为示例构建、设定随机种子的小规模模拟数据——绝非论文的数据或结果。每个条目给出完整文献以及以其为背景的图表。元分析森林图和漏斗图是例外:它们使用一张手工录入的真实已发表表格。

  • 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.
    使用于: 元分析森林图, 漏斗图
  • Sanger & Warin (2019), similarity of European party manifestos. Sanger, W., & Warin, T. (2019). Dataset of Jaccard similarity indices from 1,597 European political manifestos across 27 countries (1945–2017). Data in Brief, 24, 103907. https://doi.org/10.1016/j.dib.2019.103907
    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.
    使用于: 带密度曲线的直方图, 聚类热图
  • 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.
    使用于: 雨云图
  • Stojkov, Warin & Kjosevski (2026), current accounts of OECD countries. Stojkov, A., Warin, T., & Kjosevski, J. (2026). Beyond the balance: An intertemporal perspective on the current accounts of OECD countries. Acta Oeconomica, 76(3), 402–429. https://doi.org/10.1556/032.2026.00539
    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.
    使用于: 山脊图
  • Pastoriza Rivas & Warin (2022), Tiger Woods press conferences and performance. Pastoriza Rivas, D., & Warin, T. (2022). Dataset of two decades of Tiger Woods press conferences and tournament performance. Data in Brief, 41, 107955. https://doi.org/10.1016/j.dib.2022.107955
    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.
    使用于: ECDF 比较
  • Warin (2021), global research on coronaviruses. Warin, T. (2021). Global research on coronaviruses: Metadata-based analysis for public health policies. JMIR Medical Informatics, 9(11), e31510. https://doi.org/10.2196/31510
    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.
    使用于: 带置信带的 Q–Q 图
  • Kouloukoui et al. (2021), perceived exposure to climate risks. Kouloukoui, D., de Marcellis-Warin, N., Armellini, F., Warin, T., & Andrade Torres, E. (2021). Factors influencing the perception of exposure to climate risks: Evidence from the world's largest carbon-intensive industries. Journal of Cleaner Production, 306, 127160. https://doi.org/10.1016/j.jclepro.2021.127160
    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.
    使用于: 组间比较, 95% 置信区间的含义
  • Warin, d'Anglade & de Marcellis-Warin (2025), data science for waste reduction in manufacturing. Warin, T., d'Anglade, P. M., & de Marcellis-Warin, N. (2025). Optimising industrial efficiency: Integrating K-means clustering and data science for sustainable manufacturing and waste reduction. International Journal of Sustainable Engineering, 18(1), 2527300. https://doi.org/10.1080/19397038.2025.2527300
    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.
    使用于: 交叉验证模型比较, 置换重要性, 带 ICE 曲线的部分依赖图, SHAP 汇总图(蜂群图), SHAP 依赖图, 单个预测的 SHAP 瀑布图, 被试内比较
  • Warin, Melchior & de Marcellis-Warin (2025), public engagement with the WHO on X. Warin, T., Melchior, C., & de Marcellis-Warin, N. (2025). Social media metrics and popular legitimacy: Content analysis of pre- and post-COVID-19 public engagement with the WHO on X. Journal of Medical Internet Research, 27, e69959. https://doi.org/10.2196/69959
    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.
    使用于: 估计图
  • de Marcellis-Warin et al. (2022), AI and consumer manipulation. de Marcellis-Warin, N., Marty, F., Thelisson, E., & Warin, T. (2022). Artificial intelligence and consumer manipulations: From consumer's counter algorithms to firm's self-regulation tools. AI and Ethics, 2(2), 259–268. https://doi.org/10.1007/s43681-022-00149-5
    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.
    使用于: 交互作用图
  • Sanger & Warin (2020), the speeches of the ECB's presidents. Sanger, W., & Warin, T. (2020). The speeches of the European Central Bank's presidents: An NLP study. Global Economy Journal, 20(2), 2050009. https://doi.org/10.1142/s2194565920500098
    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.
    使用于: Tukey HSD 区间
  • Melchior, Warin & Oliveira (2026), survey on COVID-19 fake-news sharing. Melchior, C., Warin, T., & Oliveira, M. (2026). Survey data on COVID-19-related fake-news sharing on Facebook. Data in Brief, 65, 112533. https://doi.org/10.1016/j.dib.2026.112533
    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.
    使用于: 发散式 Likert 图
  • Sanger & Warin (2018), the 2014 Québec election on Twitter. Sanger, W., & Warin, T. (2018). The public's perception of political parties during the 2014 Québec election on Twitter. Canadian Journal of Communication, 43(2), 245–263. https://doi.org/10.22230/cjc.2018v43n2a3251
    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.
    使用于: 按组堆叠的比例图
  • Stojkov & Warin (2023), the refugee crisis on Twitter. Stojkov, A., & Warin, T. (2023). Discursive dynamics and local contexts on Twitter: The refugee crisis in Europe. Discourse & Communication, 17(3), 354–380. https://doi.org/10.1177/17504813231155739
    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.
    使用于: 带 Pearson 残差的马赛克图
  • Kouloukoui, de Marcellis-Warin & Warin (2025), corporate climate transition plans. Kouloukoui, D., de Marcellis-Warin, N., & Warin, T. (2025). Barriers, opportunities and best practices for corporate climate transition plans: A literature review. Climate, 13(5), 88. https://doi.org/10.3390/cli13050088
    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.
    使用于: 带置信区间的比例
  • Kouloukoui et al. (2023), global conversations on ESG topics. Kouloukoui, D., de Marcellis-Warin, N., Gomes, S. M. S., & Warin, T. (2023). Mapping global conversations on twitter about environmental, social, and governance topics through natural language processing. Journal of Cleaner Production, 414, 137369. https://doi.org/10.1016/j.jclepro.2023.137369
    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.
    使用于: 带指标的混淆矩阵, 带标准化残差的交叉表
  • Stojkov & Warin (2019), the Mundellian trilemma dataset. Stojkov, A., & Warin, T. (2019). Navigating through the Mundellian trilemma: A dataset of four decades. Data in Brief, 27, 104677. https://doi.org/10.1016/j.dib.2019.104677
    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.
    使用于: 相关矩阵
  • Janicki, Warin & Wunnava (2009), endogenous optimum currency areas. Janicki, H., Warin, T., & Wunnava, P. (2009). Testing Mundell's intuition of endogenous OCA theory. Review of International Economics, 17(1), 74–86. https://doi.org/10.1111/j.1467-9396.2008.00802.x
    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.
    使用于: 附统计量的散点图, 工具变量表
  • Hadengue & Warin (2014), specialisation and convergence in Brazil, China and India. Hadengue, M., & Warin, T. (2014). Patterns of specialization and (un)conditional convergence: The cases of Brazil, China and India. Management international, 18, 123–141. https://doi.org/10.7202/1027869ar
    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.
    使用于: 附相关系数的配对图
  • Dedinec, Stojkov, Warin & Kocarev (2026), the development compression trap. Dedinec, A., Stojkov, A., Warin, T., & Kocarev, L. (2026). The development compression trap: A framework for understanding uneven development trajectories. Journal of Sustainable Development of Energy, Water and Environment Systems, 15(1).
    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.
    使用于: 带聚类的相关图
  • Stojkov, Veljanovski & Warin (2024), European integration and growth in emerging Europe. Stojkov, A., Veljanovski, M., & Warin, T. (2024). European integration and economic growth in emerging Europe: The role of institutions and policy factors. Post-Communist Economies, 36(7), 778–800. https://doi.org/10.1080/14631377.2024.2376974
    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.
    使用于: 系数图, stargazer 风格的回归表
  • Blakely & Warin (2012), the decision to migrate in Europe. Blakely, A., & Warin, T. (2012). Choice or mimetism in the decision to migrate? A European illustration. Global Economy Journal, 12(2). https://doi.org/10.1515/1524-5861.1818
    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.
    使用于: 优势比森林图, 描述性统计表
  • Stojkov & Warin (2018), EU membership and FDI. Stojkov, A., & Warin, T. (2018). EU membership and FDI: Is there an endogenous credibility effect? Journal of East-West Business, 24, 144–169. https://doi.org/10.1080/10669868.2018.1431579
    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.
    使用于: 嵌套模型比较, 面板数据回归表
  • Kouloukoui, de Marcellis-Warin & Warin (2025), public perceptions of AI. Kouloukoui, D., de Marcellis-Warin, N., & Warin, T. (2025). Balancing risks and benefits: Public perceptions of AI through traditional surveys and social media analysis. AI & Society, 40(6), 4919–4942. https://doi.org/10.1007/s00146-025-02232-x
    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.
    使用于: 预测概率
  • Stojkov & Warin (2021), foreign capital and domestic funding conditions. Stojkov, A., & Warin, T. (2021). Foreign capital and domestic funding conditions: A Mundellian trilemma perspective. Global Economy Journal, 21, 2150008. https://doi.org/10.1142/s2194565921500081
    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.
    使用于: 交互效应
  • Troadec & Warin (2015), Canadian firms in global R&D. Troadec, A., & Warin, T. (2015). La place des entreprises canadiennes dans la R-D mondiale. In B. Sinclair-Desgagné, A. Van Assche & T. Warin (Eds.), L'économie du Québec 2015 : contexte et enjeux internationaux (ch. 4, pp. 109–125). Presses internationales Polytechnique.
    The example is set in the context of this chapter; unless its description says otherwise, the numbers are simulated and are not the chapter's data or results.
    使用于: 分位数回归过程
  • Tengia, Wandschneider, Warin & Wunnava (2011), Southern African trade integration. Tengia, O., Wandschneider, K., Warin, T., & Wunnava, P. (2011). Southern African economic integration: Evidence from an augmented gravity model. African Finance Journal, 13(1).
    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.
    使用于: 残差诊断, 添加变量图
  • Warin & Stojkov (2021), banks' foreign claims after the 2008 crisis. Warin, T., & Stojkov, A. (2021). Banks' foreign claims in the aftermath of the 2008 crisis: Institutional response, financial efficiency, and integration of cross-border banking in the euro area. Journal of Risk and Financial Management, 14(2), 61. https://doi.org/10.3390/jrfm14020061
    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.
    使用于: 影响图
  • Marty & Warin (2025), algorithmic collusion and antitrust. Marty, F., & Warin, T. (2025). Deciphering algorithmic collusion: Insights from bandit algorithms and implications for antitrust enforcement. Journal of Economy and Technology, 3, 34–43. https://doi.org/10.1016/j.ject.2024.10.001
    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.
    使用于: ROC 曲线, 双重差分表
  • Zarea et al. (2026), supply-chain resilience and digitalisation. Zarea, H., Moghaddamzadeh, H., Moradi, M., Hassani, A., Warin, T., & Stojkov, A. (2026). Risk-driven capability development in global supply chain resilience: Implications for digitalization. Journal of Information Technology Management, 82–107. https://jitm.ut.ac.ir/article_108005.html
    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.
    使用于: 校准图
  • Vorreuther & Warin (2021), patent velocity in China's pharmaceutical industry. Vorreuther, C. M., & Warin, T. (2021). Patent relatedness and velocity in the Chinese pharmaceutical industry: A dataset of Jaccard similarities. Data in Brief, 35, 106814. https://doi.org/10.1016/j.dib.2021.106814
    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.
    使用于: Kaplan–Meier 生存曲线, Cox 风险比, 调整后的生存曲线
  • Hadengue, de Marcellis-Warin & Warin (2015), reverse innovation in pharmaceuticals. Hadengue, M., de Marcellis-Warin, N., & Warin, T. (2015). Reverse innovation and reverse technology transfer: From made in China to discovered in China in the pharmaceutical sector. Management international, 19(4), 49–69. https://doi.org/10.7202/1043076ar
    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.
    使用于: 累积风险
  • Warin (2024), Statistics Canada's open economic data for teaching. Warin, T. (2024). Access Statistics Canada's open economic data for statistics and data science courses. Technology Innovations in Statistics Education, 15(1). https://doi.org/10.5070/t5.1868
    The example is set in the context of this paper; unless its description says otherwise, the numbers are simulated and are not Statistics Canada's figures.
    使用于: STL 分解, SARIMA 预测, 季节子序列图
  • Warin & Stojkov (2023), sovereign bond yield differentials in Europe. Warin, T., & Stojkov, A. (2023). Sovereign bond yield differentials across Europe: A structural entropy perspective. Entropy, 25(4), 630. https://doi.org/10.3390/e25040630
    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.
    使用于: ACF 与 PACF
  • Stojkov & Warin (2025), the Western Balkans and the future of Europe. Stojkov, A., & Warin, T. (2025). Western Balkans and the future of Europe. Springer. https://doi.org/10.1007/978-3-031-86465-0
    The example is set in the context of this book; unless its description says otherwise, the numbers are simulated and are not the book's data or results.
    使用于: PCA 双标图
  • Aubert et al. (2026), digital skills in Canadian jobs. Aubert, B., Bourdeau, S., Warin, T., Schneider, J., & Sénegas, T. (2026). Digital skills assessment in jobs in Canada. Journal for Labour Market Research, 60(1), 18. https://doi.org/10.1186/s12651-026-00440-6
    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.
    使用于: 碎石图
  • Chaffa & Warin (2026), industrial clusters from growth co-movement. Chaffa, L., & Warin, T. (2026). Identifying industrial clusters through growth co-movement with unsupervised learning methods. GeoJournal, 91(1), 16. https://doi.org/10.1007/s10708-025-11564-6
    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.
    使用于: k-means 轮廓图
  • Leiter & Warin (2012), price dispersion on the internet. Leiter, D., & Warin, T. (2012). Homogenous goods markets: An empirical study of price dispersion on the internet. International Journal of Economics and Business Research, 4(5), 514. https://doi.org/10.1504/ijebr.2012.048776
    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.
    使用于: 自助法分布
  • Bisson & Warin (2026), AI-assisted reading of IPCC synthesis reports. Bisson, C., & Warin, T. (2026). AI-assisted longitudinal comparison of scenario knowledge representation in IPCC synthesis reports. PLOS Climate, 5(7), e0000965. https://doi.org/10.1371/journal.pclm.0000965
    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.
    使用于: Bland–Altman 图
  • Melchior, Warin & Oliveira (2025), COVID-19 fake-news sharing on Facebook. Melchior, C., Warin, T., & Oliveira, M. (2025). An investigation of the COVID-19-related fake news sharing on Facebook using a mixed methods approach. Technological Forecasting and Social Change, 213, 123969. https://doi.org/10.1016/j.techfore.2024.123969
    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.
    使用于: 精确率–召回率曲线, 学习曲线, 机器学习模型比较表
  • CIRANO GVCdtLab, digital twin of the Great Lakes–St. Lawrence corridor. CIRANO. GVCdtLab: Digital twin of the Great Lakes–St. Lawrence trade and transport corridor (researcher in charge: T. Warin). Supported by Transport Canada's National Trade Corridors Fund; research on hydrological change, maritime traffic and trade funded by the Fonds de recherche du Québec. https://cirano.qc.ca/en/research/pole/Transport
    The examples are set in the context of the lab's work; the hexagonal zones form a schematic map of the corridor and the values are simulated — they are not the lab's data, geography or results.
    使用于: 带空间权重的分级统计地图, 莫兰散点图(全局自相关), LISA 聚类地图(局部自相关), 空间相关图

这些示例用于说明统计方法。除条目另有说明外,其数值均为模拟数据,图表标题描述的是该图在这些模拟数据中呈现的内容——既不是所引论文的结论,也不是作者对实质问题的立场。关于结果、背景和数据,请以此处引用的论文为准。