数据可视化(2)seaborn

2018-05-31  本文已影响0人  MWhite

seaborn

import seaborn as sns


sns.countplot(reviews['points'])
sns.kdeplot(reviews.query('price < 200').price)
reviews.query('price < 200') 与 reviews[reviews['price']<200] 等价
A KDE plot is better than a line chart for getting the "true shape" of interval data 更平滑
image.png
image.png
sns.kdeplot(reviews[reviews['price'] < 200].loc[:, ['price', 'points']].dropna().sample(5000))

sns.distplot(reviews['points'], bins=10, kde=False)


image.png

sns.jointplot(x='price', y='points', data=reviews[reviews['price'] < 100])

image.png

sns.jointplot(x='price', y='points', data=reviews[reviews['price'] < 100], kind='hex', gridsize=20)

df = reviews[reviews.variety.isin(reviews.variety.value_counts().head(5).index)]
前五种类的数据
sns.boxplot(
x='variety',
y='points',
data=df
)

sns.violinplot(
x='variety',
y='points',
data=reviews[reviews.variety.isin(reviews.variety.value_counts()[:5].index)]
)

双变量 faceting

df = footballers[footballers['Position'].isin(['ST', 'GK'])]
g = sns.FacetGrid(df, col="Position", col_wrap=6)
g.map(sns.kdeplot, "Overall")


image.png

g = sns.FacetGrid(df, row="Position", col="Club")
g.map(sns.violinplot, "Overall")

sns.pairplot(footballers[['Overall', 'Potential', 'Value']])


image.png

fig, (axis1,axis2,axis3) = plt.subplots(1,3,figsize=(15,5))
sns.countplot(x='Embarked', data=titanic_df, ax=axis1)
sns.countplot(x='Survived', hue="Embarked", data=titanic_df, order=[1,0], ax=axis2)
embark_perc = titanic_df[["Embarked", "Survived"]].groupby(['Embarked'],as_index=False).mean()
sns.barplot(x='Embarked', y='Survived', data=embark_perc,order=['S','C','Q'],ax=axis3)


上一篇 下一篇

猜你喜欢

热点阅读