Python中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()

 

 

 

  • 4
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值