How to pass weight argument to seaborn jointplot () or to base kdeplot?

I am trying to create a shared plot with seaborn using the following code:

import seaborn as sns 
import pandas as pd
import numpy as np
import matplotlib.pylab as plt

testdata = pd.DataFrame(np.array([[100, 1, 3], [5, 2, 6], [25, 3, -4]]), index=['A', 'B', 'C'], columns=['counts', 'X', 'Y'])
counts = testdata['counts'].values
sns.jointplot('X', 'Y', data=testdata, kind='kde', joint_kws={'weights':counts})
plt.savefig('test.png')

Now it joint_kwsdoes not cause an error, but the weights are not taken into account, as can be seen in the graph:

I also tried to do this with JointGridby passing weights to limit distributions:

g = sns.JointGrid('X', 'Y', data=testdata)
x = testdata['X'].values
y = testdata['Y'].values
g.ax_marg_x.hist(x, bins=np.arange(-10,10), weights=counts)
g.ax_marg_y.hist(y, bins=np.arange(-10,10), weights=counts, orientation='horizontal')
g.plot_marginals(sns.distplot)
g.plot_join(sns.kdeplot, joint_kws={'weights':counts})
plt.savefig('test.png')

But this only works for marginal distributions, while the aggregate schedule is still not weighted:

Does anyone know how to do this?

+5
source share
2 answers

Unfortunately, this seems impossible.

feature request filed in December 2015 but was closed as a non-fix.

StackOverflow : seaborn distplot?

0

.

, , , ( ):

def jointplot(x, y, data=None, ..., joint_kws):
    g = sns.JointGrid(...)
    g.plot_joint(..., **joint_kws)

, g.plot_joint , kwargs:

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

testdata = pd.DataFrame(
    np.array([[100, 1, 3], [5, 2, 6], [25, 3, -4]]), 
    index=['A', 'B', 'C'], 
    columns=['counts', 'X', 'Y']
)
counts = testdata['counts'].values

g = sns.JointGrid('X', 'Y', data=testdata)
g.plot_marginals(sns.distplot)
g.plot_joint(sns.kdeplot, weights=counts)

enter image description here

, , barf, - .

-1

Source: https://habr.com/ru/post/1588948/


All Articles