首页 文章

在seaborn的配对图中,直方图的高度是多少?

提问于
浏览
2

我有一个关于直方图的y轴的问题,它是在带有seaborn的默认配对图中生成的 .

这是一些示例代码:

import pandas as pd
import seaborn as sns
import numpy as np

data = [np.random.random_sample(20), np.random.random_sample(20)]
dataFrame = pd.DataFrame(data=zip(*data))
g = sns.pairplot(dataFrame)
g.savefig("test.png", dpi=100)

对角线放置直方图中y轴的单位是多少?如何在此视图中读取bin的高度?

非常感谢你,
克里斯

1 回答

  • 4

    默认情况下, pairplot 使用对角线"show the univariate distribution of the data for the variable in that column"(http://stanford.edu/~mwaskom/software/seaborn/generated/seaborn.pairplot.html) .

    因此,每个条形表示相应bin中的值的计数(可以从X轴获得) . 但是,Y轴与实际计数不对应,而是对应于散点图 .

    我无法从 PairPlot 本身获取数据,但如果你没有另外说明,seaborn使用 plt.hist() 来生成该对角线,因此你可以使用以下方法获取数据:

    import matplotlib.pyplot as plt
    %matplotlib inline
    import pandas as pd
    import seaborn as sns
    import numpy as np
    
    data = [np.random.random_sample(20), np.random.random_sample(20)]
    dataFrame = pd.DataFrame(data=zip(*data))
    g = sns.pairplot(dataFrame)
    

    enter image description here

    # for the first variable:
    c, b, p = plt.hist(dataFrame.iloc[:,0])
    print c
    # [ 3.  6.  0.  2.  3.  0.  1.  3.  1.  1.]
    

    enter image description here

相关问题