Python - 你能绘制带等高线的直方图吗?
Python - can you plot a histogram with a contour?
我想用这样的等高线绘制直方图
我在 here 中找到了这张图片,但按照相同的步骤后,我没有得到轮廓。
我在堆栈溢出中看到 问题,但它在每个条上绘制了一条边,我只想要外部轮廓。
这个外轮廓怎么画? (我是 运行 python 3)
该图可能是使用不同的(即较旧的)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()
我想用这样的等高线绘制直方图
我在 here 中找到了这张图片,但按照相同的步骤后,我没有得到轮廓。
我在堆栈溢出中看到
这个外轮廓怎么画? (我是 运行 python 3)
该图可能是使用不同的(即较旧的)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()