绘制联合分布

时间:2014-11-06 21:23:29

标签: python matplotlib pandas seaborn

我的pandas数据集包含整数和浮点值:

>>> df2[['AGE_REF', 'RETSURV']].dtypes
AGE_REF      int64
RETSURV    float64
dtype: object

我想用大熊猫策划联合发行。我没有看到一种简单的熊猫形象可视化联合分布,但我偶然发现了seaborn。所以我尝试调整我已经为我的目的找到的代码:

>>> import seaborn as sns
>>> sns.jointplot('AGE_REF', "RETSURV", df2,
              kind="hex")
Traceback (most recent call last):
  File "<input>", line 2, in <module>
  File "/usr/local/lib/python2.7/site-packages/seaborn/distributions.py", line 969, in jointplot
    gridsize = int(np.mean([x_bins, y_bins]))
OverflowError: cannot convert float infinity to integer

我找到了一个相关的bug report,所以我尝试按照那里的解决方法 - 没有成功:

>>> sns.jointplot('AGE_REF', "RETSURV", df2,
              kind="hex", marginal_kws={"bins": 10})
Traceback (most recent call last):
  File "<input>", line 2, in <module>
  File "/usr/local/lib/python2.7/site-packages/seaborn/distributions.py", line 969, in jointplot
    gridsize = int(np.mean([x_bins, y_bins]))
OverflowError: cannot convert float infinity to integer

1 个答案:

答案 0 :(得分:1)

默认的hexbin gridsize使用与直方图相同的参考规则计算,因此如果您的数据以某种方式违反这些假设,您也需要直接设置:

sns.jointplot(x, y, kind="hex",
              joint_kws={"gridsize": 10},
              marginal_kws={"bins": 10})