Seaborn:使用boxplot导致内存不足

Roc*_*etq 4 python out-of-memory boxplot python-2.7 seaborn

我想为1,2和3 weight_cat值绘制三个箱图(这些是它唯一的不同值).这些箱图应显示重量类别(weight_cat)的依赖性高度.

所以我有这样一个数据帧:

print data.head(5)

        Height    Weight  weight_cat
Index                                
1      65.78331  112.9925           1
2      71.51521  136.4873           2
3      69.39874  153.0269           3
4      68.21660  142.3354           2
5      67.78781  144.2971           2
Run Code Online (Sandbox Code Playgroud)

下面的代码终于吃掉了我的所有内存.这是不正常的,我相信:

Seaborn.boxplot(x="Height", y="weight_cat", data=data)
Run Code Online (Sandbox Code Playgroud)

这有什么不对?这是手册的链接.数据帧的形状是(25000,4).这是csv文件的链接.

这是你如何获得相同的数据:

data = pd.read_csv('weights_heights.csv', index_col='Index')
def weight_category(weight):
    newWeight = weight
    if newWeight < 120:
        return 1

    if newWeight >= 150:
        return 3

    else:
        return 2

data['weight_cat'] = data['Weight'].apply(weight_category)
Run Code Online (Sandbox Code Playgroud)

iul*_*ian 5

交换xy列名称:

import seaborn as sns
sns.boxplot(x="weight_cat" y="Height", data=data)
Run Code Online (Sandbox Code Playgroud)

目前,您正在尝试创建一个包含尽可能多的箱图的图表,因为有不同的高度值(24503).

这对我的数据有用:

在此输入图像描述

编辑

如果要水平显示箱线图,可以使用orient参数提供方向:

sns.boxplot(x='Height', y='weight_cat', data=data, orient='h')
Run Code Online (Sandbox Code Playgroud)

请注意,在这种情况下,交换xy标签(如您的问题).