箱型图
import pandas as pd
import seaborn as sns
titanic=pd.read_csv('C:\\work\\titanic.csv')
titanic.head()
点击查看详情
# age列
sns.boxplot(y=titanic["age"])
点击查看详情
# x轴指定class分类
sns.boxplot(data=titanic,y="age",x="class")
点击查看详情
# 添加条件,hue
sns.boxplot(data=titanic, x="class", y="age", hue="alive")
点击查看详情
# 宽度
sns.boxplot(data=titanic, x="deck", y="age", width=.5)
点击查看详情
# 颜色 color="red"
# 线宽度
sns.boxplot(data=titanic, x="deck", y="age", color="0.8", linewidth=.75)
点击查看详情
热力图
glue=pd.read_csv('C:\\work\\glue.csv')
glue.head()
点击查看详情
# 行,列,值
glue_pivot=glue.pivot(index="Model", columns="Task", values="Score")
glue_pivot.head()
点击查看详情
sns.heatmap(glue_pivot, annot=True)
点击查看详情
# 样式
# 最小/最大
sns.heatmap(glue_pivot, annot=True, linewidth=.5, vmin=0, vmax=100)
点击查看详情
# 颜色
sns.heatmap(glue_pivot, cmap="crest", annot=True)
点击查看详情
点击查看详情
crash=pd.read_csv('C:\\work\\car_crashes.csv')
crash_tmp=crash.drop("abbrev",axis=1)
crash_tmp.head()
# 相关系数
crash_relate=crash_tmp.corr()
crash_relate
# 颜色浅的,相关系数高
sns.heatmap(crash_relate, annot=True, linewidth=0.5)
多变量联合分布图
penguins=pd.read_csv('C:\\work\\penguins.csv')
penguins.head()
点击查看详情
sns.pairplot(penguins)
点击查看详情
sns.pairplot(penguins, hue="species")
点击查看详情
sns.pairplot(penguins, kind="hist")
点击查看详情
# 高度
sns.pairplot(penguins,height=1.5)
点击查看详情
# 自定义
sns.pairplot(
penguins,
x_vars=["bill_length_mm","bill_depth_mm"],
y_vars=["bill_length_mm","bill_depth_mm"]
)
点击查看详情
sns.jointplot(data=penguins,x="bill_length_mm", y="bill_depth_mm")
点击查看详情
sns.jointplot(data=penguins, x="bill_length_mm", y="bill_depth_mm", hue="sex")
点击查看详情
# 联合分布,概率密度曲线
sns.jointplot(data=penguins, x="bill_length_mm", y="bill_depth_mm", kind="reg")
点击查看详情
sns.jointplot(data=penguins, x="bill_length_mm", y="bill_depth_mm", kind="hex")
点击查看详情
# ['scatter', 'hist', 'hex', 'kde', 'reg', 'resid']
sns.jointplot(data=penguins, x="bill_length_mm", y="bill_depth_mm", kind="scatter")
点击查看详情
回归图
mpg=pd.read_csv('C:\\work\\mpg.csv')
mpg.head()
点击查看详情
# 回归线
sns.regplot(data=mpg, x="weight", y="acceleration")
点击查看详情
sns.regplot(data=mpg, x="weight", y="acceleration", order=2)
点击查看详情
sns.regplot(data=mpg, x="weight", y="acceleration", order=3)
点击查看详情
# marker指定x或o
sns.regplot(
data=mpg, x="weight", y="acceleration",
marker="x", color=".3", line_kws=dict(color="red")
)
点击查看详情
penguins=pd.read_csv('C:\\work\\penguins.csv')
penguins.head()
点击查看详情
# 不同数值变量在多个分类变量下的关系
sns.lmplot(
data=penguins, x="bill_length_mm", y="bill_depth_mm",
col="species",row="sex", height=3
)
点击查看详情
sns.lmplot(
data=penguins, x="bill_length_mm", y="bill_depth_mm",
hue="species", col="sex", height=4,
)
点击查看详情
多绘图网格
tips=pd.read_csv('C:\\work\\tips.csv')
tips.head()
点击查看详情
sns.FacetGrid(tips, col="time", row="sex")
点击查看详情
g = sns.FacetGrid(tips, col="time", row="sex")
g.map(sns.scatterplot, "total_bill","tip")
点击查看详情
g=sns.FacetGrid(tips, col="time", hue="sex")
g.map_dataframe(sns.scatterplot, x="total_bill", y="tip")
g.add_legend()
点击查看详情