Seaborn 可视化

关联图 类别图 分布图

回归图 矩阵图 组合图

使用matplotlib实现

import matplotlib.pyplot as plt
%matplotlib inline

x = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]
y_bar = [3, 4, 6, 8, 9, 10, 9, 11, 7, 8]
y_line = [2, 3, 5, 7, 8, 9, 8, 10, 6, 7]

plt.bar(x, y_bar)
plt.plot(x, y_line, '-o', color='y')

在这里插入图片描述
使用seaborn实现

import seaborn as sns

sns.set()  # 申明使用  seaborn默认样式

plt.bar(x, y_bar)
plt.plot(x, y_line, '-o', color='y')

在这里插入图片描述
sns.set(context=‘notebook’, style=‘darkgrid’, palette=‘deep’, font=‘sans-serif’, font_scale=1,
color_codes=False, rc=None)
context 控制默认画幅的大小, (‘paper’, ‘notebook’, ‘talk’,‘poster’), poster > talk > notebook > paper
style 控制默认的样式 (darkgrid, whitegrid, dark, white, ticks)
palette 设置预设的调色板 可以传(deep, muted, bright, pastel, dark, colorblind)
font 设置字体 font_scale字体大小

Seaborn常用的绘图api

关联图
•relplot 绘制关系图
•scatterplot 绘制多维度关系散点图
•lineplot 多维度的分析线性图

#  relplot  散点图、条形图两种样式

iris = sns.load_dataset('iris')
iris.head()

在这里插入图片描述

sns.set()

sns.relplot(x='sepal_length', y='sepal_width', data=iris)

在这里插入图片描述

sns.relplot(x='sepal_length', y='sepal_width',hue='species', data=iris)

在这里插入图片描述

sns.relplot(x='sepal_length', y='sepal_width',hue='species',style='species', data=iris)

在这里插入图片描述

sns.relplot(x='sepal_length', y='sepal_width',hue='species',style='species',kind='line', data=iris)

在这里插入图片描述
seaborn 有两类方法 Figure-level 和 Axes-level
Figure-level ‘懒人函数’, 适用于快速应用
Axes-level 和matplotlib结合的更紧密, 可以让两者结合 更灵活的绘图
relplot -> Figure-level
lineplot -> Axes-level

sns.lineplot(x='sepal_length', y='sepal_width',hue='species',style='species', data=iris)

在这里插入图片描述

类别图

•catplot -> Figure-level

sns.catplot(x='sepal_length', y='species', data=iris)

在这里插入图片描述

sns.catplot(x='sepal_length', y='species',kind='swarm', data=iris)

在这里插入图片描述

sns.catplot(x='sepal_length', y='species',kind='box', data=iris)  # 箱型图

在这里插入图片描述

# 小提琴图
sns.catplot(x='sepal_length', y='species',kind='violin', data=iris)

在这里插入图片描述

sns.catplot(x='sepal_length', y='species',kind='boxen', data=iris)

在这里插入图片描述

# 绘制点线图
sns.catplot(x='sepal_length', y='species',kind='point', data=iris)

在这里插入图片描述

# 条形图
sns.catplot(x='sepal_length', y='species',kind='bar', data=iris)

在这里插入图片描述

# 计数条形图
sns.catplot(x='species',kind='count', data=iris)

在这里插入图片描述

分布图

•joinplot
•pairplot
•distplot
•kdeplot

sns.distplot(iris['sepal_length'])    # 直方图  和  概率密度图

在这里插入图片描述

sns.kdeplot(iris['sepal_length'])     # 概率密度图

在这里插入图片描述

sns.jointplot(x='sepal_length', y='sepal_width', data=iris)

在这里插入图片描述

sns.jointplot(x='sepal_length', y='sepal_width', data=iris, kind='kde')

在这里插入图片描述

# 回归拟合图
sns.jointplot(x='sepal_length', y='sepal_width', data=iris, kind='reg')

在这里插入图片描述

sns.pairplot(iris)  # 二元变量分布图

在这里插入图片描述

sns.pairplot(iris, hue='species')

在这里插入图片描述

# 回归图

sns.lmplot(x='sepal_length', y='sepal_width', hue='species', data=iris)

在这里插入图片描述

# 矩阵图

import numpy as np

numpy_temp = np.random.rand(10,10)
numpy_temp

在这里插入图片描述

sns.heatmap(numpy_temp)

在这里插入图片描述
虽然不完全,但我觉得也挺多的,这要怎么记呀

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值