Python - 你能用等高线绘制直方图吗?

bob*_*eno 4 python matplotlib histogram draw

我想用这样的轮廓绘制直方图 在此处输入图片说明

我在这里找到了这张图片,但在按照相同的程序之后,我没有得到轮廓。

我在堆栈溢出中看到了这个问题,但它在每个条形上画了一条边,我只想要外轮廓。

我怎样才能画出这个外轮廓?(我正在运行 python 3)

Imp*_*est 8

该图可能是用不同的(即较旧的)matplotlib 版本生成的。这也可以从 的使用中看出normed,它在较新的版本中已被弃用。

在这里,您可以明确地将边缘颜色设置为黑色。 ec="k",或更长时间,edgecolor="black"

import numpy as np
import matplotlib.pyplot as plt
plt.style.use('seaborn-white')

x1 = np.random.normal(0, 0.8, 1000)
x2 = np.random.normal(-2, 1, 1000)
x3 = np.random.normal(3, 2, 1000)

kwargs = dict(histtype='stepfilled', alpha=0.3, density=True, bins=40, ec="k")

plt.hist(x1, **kwargs)
plt.hist(x2, **kwargs)
plt.hist(x3, **kwargs);

plt.show()
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明