简体   繁体   English

地块分布

[英]Plot joint distribution

I'm having a pandas dataset that contains an integer and a float value: 我有一个pandas数据集,其中包含一个整数和一个浮点值:

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

I'd like to plot the joint distribution using pandas. 我想用熊猫绘制联合分布。 I didn't see a simple way of pandas visualizing the joint distribution, but I stumbled across seaborn . 我没有看到简单的熊猫可视化关节分布的方法,但是我偶然发现了seaborn So I tried to adjust code that I already found for my purposes: 因此,我尝试调整已经为我的目的找到的代码:

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

I found a related bug report , so I tried to follow the workaround there - without success: 我找到了一个相关的错误报告 ,因此我尝试遵循那里的解决方法-没有成功:

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

The default hexbin gridsize uses the same reference rule calculation as the histograms, so you'll need to set that directly too if you have data that violate those assumptions somehow: 默认的hexbin gridsize使用与直方图相同的参考规则计算,因此,如果您有某种方式违反这些假设的数据,则也需要直接设置该值:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM