1

当我制作一个将 shade 参数设置为 True 的 seaborn.kdeplot 时,背景是白色的。如果在更宽的范围(此处为蓝线)上绘制了其他内容,则此背景不会扩展到整个图。如何让 kdeplot “扩展到”整个情节?

(最终,让 kdeplot 的第一个阴影是透明的也可以解决问题)

这个例子:

import seaborn as sns
import numpy as np
import matplotlib.pyplot as plt

plt.plot([-3, 3],[0,60])

points = np.random.multivariate_normal([0, 0], [[1, 2], [2, 20]], size=1000)
sns.kdeplot(points, shade=True)

plt.show()

蓝线的 Overplot 和一组点的 kdeplot。 注意 y=20 时背景的变化

4

2 回答 2

2

这样可行:

import seaborn as sns
import numpy as np
import matplotlib.pyplot as plt

points = np.random.multivariate_normal([0, 0], [[1, 2], [2, 20]], size=1000)

plt.plot([-3, 3],[0,60])

ax = sns.kdeplot(points, shade=True)
ax.collections[0].set_alpha(0)

plt.show()

在此处输入图像描述

于 2015-01-20T16:23:42.333 回答
-1

set_style那么你可以通过使用参数来做到这一点

import seaborn as sns
import numpy as np
import matplotlib.pyplot as plt

plt.plot([-3, 3],[0,60])

points = np.random.multivariate_normal([0, 0], [[1, 2], [2, 20]], size=1000)
sns.kdeplot(points)
sns.set_style("white") # HERE WE SET THE BACKGROUND TO BE WHITE

plt.show()

上面的代码将生成如下图:

在此处输入图像描述

于 2014-12-08T17:04:55.463 回答