[英]seaborn point plot visualization
I am plotting a point plot to show the relationship between "workclass", "sex", "occupation" and "Income exceed 50K or not".我正在绘制一个点图来显示“工人阶级”、“性别”、“职业”和“收入是否超过 50K”之间的关系。 However, the result is a mess.然而,结果却是一团糟。 The legends are stick together, Female and Male are both shown in blue colors in the legend etc.传说是粘在一起的,女性和男性在传说中都以蓝色显示,等等。
#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()
Please advise how to fit the size of the plot.请告知如何适应地块的大小。 Thanks!谢谢!
It sounds like 'exceeds50k' is a categorical variable.听起来 'exceeds50k' 是一个分类变量。 Your y variable needs to be continuous for a point plot.对于点图,您的 y 变量需要是连续的。 So assuming this is your dataset:所以假设这是你的数据集:
import pandas as pd
import seaborn as sns
df =pd.read_csv("https://raw.githubusercontent.com/katreparitosh/Income-Predictor-Model/master/Database/adult.csv")
We simplify some categories to plot for example sake:我们简化了一些类别来绘制例如:
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
If the y variable is categorical, you might want to use a barplot:如果 y 变量是分类变量,您可能需要使用条形图:
sns.catplot(hue='income',x='sex', palette='deep',data=df,
col='native.country',
row='race',kind='count',height=3,aspect=1.6)
If it is continuous, for example age, you can see it works:如果它是连续的,例如年龄,您可以看到它的工作原理:
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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.