Seabon画图总结

这里简单介绍一下常用的图。

引入接下来可能用到的头文件:

import numpy as np
import pandas as pd
from scipy import stats
import matplotlib.pyplot as plt
import seaborn as sns

数据关系可视化:

heatmaps:

这一个还是比较好用还有重要的,机器学习选取特征时候常常用它很方便的可以看到各个特征的相关性大小:

df = pd.read_csv('./test.csv') #引用的Kaggle的我处理过的泰坦尼克号的数据作为例子
df_corr = df.corr() #corr()是算两两特征之间的相关性,返回一个相关性矩阵
sns.heatmap(df_corr, annot=True) #annot显示相关性的大小
plt.show()
Heapmaps

 

pairplot:

这个也可以很方便的查看各个特征之间的关系

dataset = sns.load_dataset('tips') #tip是一个sns里面带的一个数据集
# print(dataset)  #可打印查看
sns.pairplot(dataset)
plt.show()

 

类别内数据分布可视化:

boxplot:

盒子图也叫箱线图,这个可以用来查看异常数据,方便数据清洗

# 盒子图
exercise = sns.load_dataset('exercise')
sns.boxplot(x="diet", y="pulse", data=exercise)
sns.boxplot(x="diet", y="pulse", data=exercise, hue='kind')
 #类似于pandas里的分组,hue:就像相当于在‘kind(哪一种运动状态)里面再进行对x="diet", y="pulse"的画图
plt.show()
hue='kind'

violinplot:

# 小提琴图
exercise = sns.load_dataset('exercise')
# sns.violinplot(x="diet", y="pulse", data=exercise)
sns.violinplot(x="diet", y="pulse", data=exercise, hue='kind')
plt.show()

类别数据可视化:

stripplot:

#类别散布图
exercise = sns.load_dataset('exercise')
sns.stripplot(x='diet', y='pulse', data=exercise)
sns.stripplot(x='diet', y='pulse', data=exercise, hue='kind') #hue和之前得hue得作用相同,都差不多相当于增加了一个维度
plt.show()

swarmplot:

这个完善了 stripplot(xxx  xxx  xxx  hue = 'xxx') 当数据为“三维”的时候的数据重叠,代码与效果如下
 

exercise = sns.load_dataset('exercise')
# sns.stripplot(x='diet', y='pulse', data=exercise)
# sns.stripplot(x='diet', y='pulse', data=exercise, hue='kind') #hue和之前得hue得作用相同,都差不多相当于增加了一个维度
sns.swarmplot(x='diet', y='pulse', data=exercise, hue='kind') #hue和之前得hue得作用相同,都差不多相当于增加了一个维度
plt.show()
 
 

 
  
 

类别内统计图:

barplot:

# 柱状图
exercise = sns.load_dataset('exercise')
sns.barplot(x="diet", y="pulse", data=exercise, hue='kind')
plt.show()

pointplot:

# 点图
exercise = sns.load_dataset('exercise')
sns.pointplot(x="diet", y="pulse", data=exercise);
# sns.pointplot(x="diet", y="pulse", data=exercise, hue='kind');
plt.show()

猜你喜欢

转载自blog.csdn.net/ltrbless/article/details/82084456