
我正在绘制一个点图来显示“工人阶级”、“性别”、“职业”和“收入是否超过50K”之间的关系。然而,结果却是一团糟。传说是粘在一起的,在传说中女性和男性都是蓝色的等等。
#Co-relate categorical features
grid = sns.FacetGrid(train, row='occupation', size=6, aspect=1.6)
grid.map(sns.pointplot, 'workclass', 'exceeds50K', 'sex', palette='deep', markers = ["o", "x"] )
grid.add_legend()请告诉我如何适应地块的大小。谢谢!
发布于 2020-11-06 06:20:28
听起来'exceeds50k‘是一个分类变量。对于点图,y变量需要是连续的。因此,假设这是您的数据集:
import pandas as pd
import seaborn as sns
df =pd.read_csv("https://raw.githubusercontent.com/katreparitosh/Income-Predictor-Model/master/Database/adult.csv")例如,我们简化了一些类别来绘制:
df['native.country'] = [i if i == 'United-States' else 'others' for i in df['native.country'] ]
df['race'] = [i if i == 'White' else 'others' for i in df['race'] ]
df.head()
age workclass fnlwgt education education.num marital.status occupation relationship race sex capital.gain capital.loss hours.per.week native.country income
0 90 ? 77053 HS-grad 9 Widowed ? Not-in-family White Female 0 4356 40 United-States <=50K
1 82 Private 132870 HS-grad 9 Widowed Exec-managerial Not-in-family White Female 0 4356 18 United如果y变量是分类变量,则可能需要使用条形图:
sns.catplot(hue='income',x='sex', palette='deep',data=df,
col='native.country',
row='race',kind='count',height=3,aspect=1.6)

如果它是连续的,例如年龄,你可以看到它是工作的:
grid = sns.FacetGrid(df, row='race', height=3, aspect=1.6)
grid.map(sns.pointplot, 'native.country', 'age', 'sex', palette='deep', markers = ["o", "x"] )
grid.add_legend()

https://stackoverflow.com/questions/64691124
复制相似问题