在RI中,可以通过以下方式创建所需的输出:
data = c(rep(1.5, 7), rep(2.5, 2), rep(3.5, 8),
rep(4.5, 3), rep(5.5, 1), rep(6.5, 8))
plot(density(data, bw=0.5))
Run Code Online (Sandbox Code Playgroud)

在python(使用matplotlib)中,我得到的最接近的是一个简单的直方图:
import matplotlib.pyplot as plt
data = [1.5]*7 + [2.5]*2 + [3.5]*8 + [4.5]*3 + [5.5]*1 + [6.5]*8
plt.hist(data, bins=6)
plt.show()
Run Code Online (Sandbox Code Playgroud)

我也尝试了normed = True参数,但除了试图将高斯拟合到直方图之外,我无法得到任何其他参数.
我最新的尝试是围绕scipy.stats和gaussian_kde,根据网站上的例子,但我一直不成功至今.
根据 seaborn 文档,这里 seaborn.distplot()已被弃用,支持的图为:seaborn.displot()和seaborn.histplot()。
但是,当我尝试使用displot()或 时histplot()出现以下属性错误:
AttributeError: module 'seaborn' has no attribute 'displot'
注意我可以成功运行seaborn.jointplot()和其他各种。
我发现这个 SO post Module Seaborn 没有属性 ''但这似乎不是我问题的解决方案。
我已经seaborn版本0.10.1我安装的MacOS版本10.15.5(19F101)
我今天早些时候有seaborn 0.9.0并且遇到了同样的问题,所以我使用App Cleaner & Uninstaller应用程序删除了我的Anaconda发行版并重新安装。现在我有seaborn 版本 0.10.1。
Anaconda的全新安装不应该处理所有依赖项和要求吗?
请参见下面的属性错误屏幕截图。任何想法发生了什么?
更新:
上面的图似乎最近才从seaborn 0.11.0开始可用。所以我正在尝试通过以下方式安装新的 seaborn:conda install seaborn==0.11.0但是conda和/或频道似乎有问题。它试图解决环境问题,但它处于永无止境的循环中。我终止了这个过程,然后再试一次,同样的事情。
(base)MacBook-Air:$ conda install seaborn==0.11.0
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial …Run Code Online (Sandbox Code Playgroud)