1

I'm trying to draw joint distribution of 2 variables in a package named seaborn (a wrapper over matplotlib). Ultimately, I want to get something like this: http://web.stanford.edu/~mwaskom/software/seaborn/examples/hexbin_marginals.html

The problem is that seaborn swears at me when I pass arrays of different lengths. Suppose,

var1 = [1,1,1,1,1,2,2,2,2,3,3,5,7]
var2 = [1,1,1,1,2,2,2,3,3,3,4,4,5,5,6,6,7,9,10,13]

Then if I write this:

import seaborn as sns
sns.jointplot(var1, var2, kind='hex')

it throws

ValueError: operands could not be broadcast together with shapes (13) (20)

Anyone knows how to make seaborn reconcile with this?

4

1 回答 1

4

TL/DR:当数组长度不同时,联合图不是定义明确的数学运算

您可以将 hexbin 视为散点图,除了绘制点之外,它会略微增加点原本会落入的六边形区域的值。显然,除非你所有的 x 都与 y 配对,否则你不能制作散点图。

数学答案:

在该图中,如果您查看顶部和右侧的直方图,那就是一维频率分布。在主窗口中绘制 2D 分布的目的是查看变量可能是如何依赖的——如果它们是独立的,那么每个 (x,y) 坐标很简单,x 变量的相对频率乘以y 变量(即f(x,y) = f(x)f(y)x,y 独立的 pdf)。

因此,如果您想了解这些变量如何偏离独立,您必须拥有关于它们的联合信息——两个变量的联合意义观察具有一个共同的索引,这里假设为 (0...i)。另请参阅wikipedia 上的独立性和Cross Validated 上的独立性标签

于 2014-10-13T12:32:20.387 回答