简体   繁体   中英

Horizontal plot in swarmplot of seaborn

Situation
I have the following pandas dataset:

|user_id|total|is_fat|
|-------|-----|------|
|1      |100  |1     |
|2      |150  |0     |
|3      |400  |1     |
|4      |500  |1     |
|5      |10   |0     |

where elements of the total are integer and elements of is_fat are string.

I denote above dataset by df .

Then run the following code:

import seaborn as sos
sns.swarmplot(x = 'total', y ='is_fat', data = df)

Now the graph I expected looks like: 在此处输入图片说明

Problem However, the output graph is the following:

在此处输入图片说明

Why?

Search
If I convert '1' to 'fat' and '0' to 'not_fat', then I get the expected graph.

I have simulated some data and changed is_fat to categorical as shown:

import seaborn as sns
import pandas as pd
import numpy as np

df = pd.DataFrame({"total":abs(np.random.randn(100)), "is_fat": [1,0]*50})
df.is_fat = df.is_fat.astype("category")
sns.swarmplot(x = 'total', y ='is_fat', data = df)

This produced the graph below: 在此处输入图片说明

I hope this helps.

对我来说,将orient="h"作为参数添加到我的swarmplot()调用中解决了这个问题(请参阅 Seaborn 文档以供参考)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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