pythonseabornkdeplot

Pass probabilities to kdeplot


Suppose I want to plot the following data using sns.kdeplot:

np.random.seed(42)
x = [np.random.randint(0, 10) for _ in range(10)]

x
[6, 3, 7, 4, 6, 9, 2, 6, 7, 4]

enter image description here

But now, instead of having each value, suppose I have the probability of each one:

# y is a pd.Series
y
6    0.3
7    0.2
4    0.2
9    0.1
3    0.1
2    0.1

Is it possible to build the kdeplot from these probabilities?

I think that seaborn probably calculate these values and thus I think it might be possible


Solution

  • You should be able to accomplish this with the weights parameter of kdeplot (added in v0.11.0), something like

    sns.kdeplot(x=x, weights=y)