1

When I make a seaborn.kdeplot with the shade parameter set as True, the background is white. This background does not extend to the whole plot if there is something else that is plotted on a wider range (here, the blue line). How can I get kdeplot to "extend" to the whole plot?

(Eventually, having the first shade of kdeplot being transoarent would also make the trick)

The example:

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 of a blue line and a kdeplot of a set of points. Notice the change in background at y=20

user2076688
  • 245
  • 3
  • 12

2 Answers2

2

That works:

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()

enter image description here

user2076688
  • 245
  • 3
  • 12
-1

Well you can do so by using the set_style parameter

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()

The code above will produce a plot like this:

enter image description here

Srivatsan
  • 9,225
  • 13
  • 58
  • 83
  • 1
    Thank you, but this works only because you don't have the parameter "shade=True" in your kdeplot. Doing the same with this parameters still returns the same problem (although I might try to set the background to the color of my first shade, which may not be trivial). – user2076688 Dec 08 '14 at 17:14