Seaborn 常用的 10 种数据分析图表

大数据 数据可视化
Seaborn内置了十几个示例数据集,通过load_dataset函数可以调用。其中包括常见的泰坦尼克、鸢尾花等经典数据集。

内置示例数据集

seaborn内置了十几个示例数据集,通过load_dataset函数可以调用。

其中包括常见的泰坦尼克、鸢尾花等经典数据集。

# 查看数据集种类 
import seaborn as sns 
sns.get_dataset_names() 
  • 1.
  • 2.
  • 3.

seaborn 常用的 10 种数据分析图表

import seaborn as sns 
# 导出鸢尾花数据集 
data = sns.load_dataset('iris') 
data.head() 
  • 1.
  • 2.
  • 3.
  • 4.

seaborn 常用的 10 种数据分析图表

1. 散点图

函数sns.scatterplot

import seaborn as sns 
sns.set() 
import matplotlib.pyplot as plt 
%matplotlib inline 
# 小费数据集 
tips = sns.load_dataset('tips') 
ax = sns.scatterplot(x='total_bill',y='tip',data=tips
plt.show() 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.

seaborn 常用的 10 种数据分析图表

2. 条形图

函数sns.barplot

显示数据平均值和置信区间

import seaborn as sns 
sns.set() 
import matplotlib.pyplot as plt 
%matplotlib inline 
# 小费数据集 
tips = sns.load_dataset("tips") 
ax = sns.barplot(x="day"y="total_bill"data=tips
plt.show() 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.

seaborn 常用的 10 种数据分析图表

3. 线型图

函数sns.lineplot

绘制折线图和置信区间

import seaborn as sns 
sns.set() 
import matplotlib.pyplot as plt 
%matplotlib inline 
fmri = sns.load_dataset("fmri") 
ax = sns.lineplot(x="timepoint"y="signal"data=fmri
plt.show() 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.

seaborn 常用的 10 种数据分析图表

4. 箱线图

函数seaborn.boxplot

import seaborn as sns 
sns.set() 
import matplotlib.pyplot as plt 
%matplotlib inline 
tips = sns.load_dataset("tips") 
ax = sns.boxplot(x="day"y="total_bill"data=tips
plt.show() 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.

seaborn 常用的 10 种数据分析图表

5. 直方图

函数seaborn.distplot

import seaborn as sns 
import numpy as np 
sns.set() 
import matplotlib.pyplot as plt 
%matplotlib inline 
np.random.seed(0) 
x = np.random.randn(1000) 
ax = sns.distplot(x) 
plt.show() 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.

seaborn 常用的 10 种数据分析图表

6. 热力图

函数seaborn.heatmap

import numpy as np 
np.random.seed(0) 
import seaborn as sns  
sns.set() 
import matplotlib.pyplot as plt 
%matplotlib inline 
uniform_data = np.random.rand(10, 12) 
ax = sns.heatmap(uniform_data) 
plt.show() 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.

seaborn 常用的 10 种数据分析图表

7. 散点图矩阵

函数sns.pairplot

import seaborn as sns 
sns.set() 
import matplotlib.pyplot as plt 
%matplotlib inline 
iris = sns.load_dataset("iris") 
ax = sns.pairplot(iris) 
plt.show() 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.

seaborn 常用的 10 种数据分析图表

8. 分类散点图

函数seaborn.catplot

import seaborn as sns 
sns.set() 
import matplotlib.pyplot as plt 
%matplotlib inline 
exercise = sns.load_dataset("exercise") 
ax = sns.catplot(x="time"y="pulse"hue="kind"data=exercise)\ 
plt.show() 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.

seaborn 常用的 10 种数据分析图表

9. 计数条形图

函数seaborn.countplot

import seaborn as sns 
sns.set() 
import matplotlib.pyplot as plt 
%matplotlib inline 
titanic = sns.load_dataset("titanic") 
ax = sns.countplot(x="class"data=titanic
plt.show() 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.

seaborn 常用的 10 种数据分析图表

10. 回归图

函数 seaborn.lmplot

绘制散点及回归图

import seaborn as sns 
sns.set() 
import matplotlib.pyplot as plt 
%matplotlib inline 
tips = sns.load_dataset("tips") 
ax = sns.lmplot(x="total_bill"y="tip"data=tips
 
plt.show() 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.

seaborn 常用的 10 种数据分析图表

责任编辑:赵宁宁 来源: 今日头条
相关推荐

2020-08-10 06:16:26

seaborn数据分析图表

2020-12-22 15:33:42

数据分析技术IT

2017-08-01 16:42:09

数据分析互联网

2020-09-08 12:48:19

数据分析图表互联网

2019-05-06 09:27:13

数据分析大数据开发数据

2020-03-23 09:53:26

大数据IT技术

2018-08-30 14:20:54

数据分析机器学习算法

2022-09-07 15:47:21

数据分析对比分析大数据

2022-08-26 16:21:47

数据分析工具运营

2020-12-07 05:51:49

数据分析数据可视化数据科学

2017-06-28 14:54:17

大数据数据分析

2024-01-26 13:23:22

数据分析指标监控型

2024-12-31 12:09:31

2023-08-01 16:01:59

可视化Seaborn

2023-11-26 17:47:00

数据分析

2020-12-08 10:27:04

数据分析技术IT

2019-07-25 14:23:36

2020-10-08 11:24:04

数据分析技术IT

2021-02-28 12:47:27

数据分析科学技术

2017-01-11 16:54:34

数据分析数据准备数据虚拟化
点赞
收藏

51CTO技术栈公众号