0

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

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

我想使用熊猫绘制联合分布。我没有看到 pandas 可视化联合分布的简单方法,但我偶然发现了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

我发现了一个相关的错误报告,所以我尝试在那里遵循解决方法 - 没有成功:

>>> 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
4

1 回答 1

1

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

sns.jointplot(x, y, kind="hex",
              joint_kws={"gridsize": 10},
              marginal_kws={"bins": 10})
于 2014-11-08T00:38:05.537 回答