seaborn常用的10种数据分析图

 

 

查看数据集种类

In [2]:
import seaborn as sns
sns.get_dataset_names()
Out[2]:
['anscombe',
 'attention',
 'brain_networks',
 'car_crashes',
 'diamonds',
 'dots',
 'exercise',
 'flights',
 'fmri',
 'gammas',
 'iris',
 'mpg',
 'planets',
 'tips',
 'titanic']
In [4]:
import seaborn as sns
sns.set()
import matplotlib.pyplot as plt
%matplotlib inline
 

导出鸢尾花数据集

In [3]:
# 通过load_dataset()函数可以调用
data = sns.load_dataset('iris')
data.head()
Out[3]:
 
 sepal_lengthsepal_widthpetal_lengthpetal_widthspecies
0 5.1 3.5 1.4 0.2 setosa
1 4.9 3.0 1.4 0.2 setosa
2 4.7 3.2 1.3 0.2 setosa
3 4.6 3.1 1.5 0.2 setosa
4 5.0 3.6 1.4 0.2 setosa
 

散点图

In [6]:
# 小费数据集
tips = sns.load_dataset('tips')
ax = sns.scatterplot(x = 'total_bill', y = 'tip', data = tips)
plt.show()
 
In [9]:
ax = sns.barplot(x = 'day', y = 'total_bill', data = tips)
plt.show()
 
 

折线图

In [22]:
tips = sns.load_dataset("tips")
ax = sns.lineplot(x = 'day', y = 'total_bill', data = tips)
plt.show()
 
 

箱线图

In [24]:
sns.boxplot(x = 'day', y = 'total_bill', data = tips)
plt.show()
 
 

直方图

In [25]:
import numpy as np
np.random.seed(0)
x = np.random.randn(1000)
ax = sns.distplot(x)
plt.show()
 
 

热力图

In [26]:
np.random.seed(1)
uniform_data = np.random.rand(10,12)
ax = sns.heatmap(uniform_data)
plt.show()
 
 

散点图矩阵

In [27]:
iris = sns.load_dataset('iris')
ax = sns.pairplot(iris)
plt.show()
 
 

分类散点图

In [30]:
sns.catplot(x = 'day', y = 'total_bill', data = tips)
plt.show()
 
 

计数条形图

In [31]:
sns.countplot(x = 'day', data = tips)
plt.show()
 
 

回归图

In [32]:
sns.lmplot(x = 'total_bill', y = 'tip', data = tips)
plt.show()
 
In [ ]:
 
In [ ]:
 
posted @ 2020-04-15 10:56  shiyadongfighting  阅读(301)  评论(0)    收藏  举报