seaborn(2)---画分类图/分布图/回归图/矩阵图
二.分类图
1. 分类散点图
(1)散点图striplot(kind='strip')
方法1:
seaborn.stripplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, jitter=True, dodge=False, orient=None, color=None, palette=None, size=5, edgecolor='gray', linewidth=0, ax=None, **kwargs)
方法2:catplot的kind默认=striplot
sns.catplot(x="sepal_length", y="species", data=iris)
(2)带分布的散点图swarmplot(kind='swarm')
方法1:
seaborn.swarmplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, dodge=False, orient=None, color=None, palette=None, size=5, edgecolor='gray', linewidth=0, ax=None, **kwargs)
方法2:
sns.catplot(x="sepal_length", y="species", kind="swarm", data=iris)
2. 分类分布图
(1)箱线图boxplot(kind='box')
方法1:
seaborn.boxplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, orient=None, color=None, palette=None, saturation=0.75, width=0.8, dodge=True, fliersize=5, linewidth=None, whis=1.5, notch=False, ax=None, **kwargs)
方法2:
sns.catplot(x="sepal_length", y="species", data=iris)
(2)小提琴图violinplot(kind='violin')
方法1:
seaborn.violinplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, bw='scott', cut=2, scale='area', scale_hue=True, gridsize=100, width=0.8, inner='box', split=False, dodge=True, orient=None, linewidth=None, color=None, palette=None, saturation=0.75, ax=None, **kwargs)
方法2:
sns.catplot(x="sepal_length", y="species", kind="violin", data=iris)
(3)boxenplot(kind='boxen')
方法1:
seaborn.boxenplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, orient=None, color=None, palette=None, saturation=0.75, width=0.8, dodge=True, k_depth='proportion', linewidth=None, scale='exponential', outlier_prop=None, ax=None, **kwargs)
方法2:
sns.catplot(x="species", y="sepal_length", kind="boxen", data=iris)
3. 分类估计图
(1)pointplot(kind='point')
方法1:
seaborn.pointplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, estimator=<function mean>, ci=95, n_boot=1000, units=None, markers='o', linestyles='-', dodge=False, join=True, scale=1, orient=None, color=None, palette=None, errwidth=None, capsize=None, ax=None, **kwargs)
方法2:
sns.catplot(x="sepal_length", y="species", kind="point", data=iris)
(2)直方图barplot(kind='bar')
方法1:
seaborn.barplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, estimator=<function mean>, ci=95, n_boot=1000, units=None, orient=None, color=None, palette=None, saturation=0.75, errcolor='.26', errwidth=None, capsize=None, dodge=True, ax=None, **kwargs)
方法2:
sns.catplot(x="sepal_length", y="species", kind="bar", data=iris)
(3)计数的直方图countplot(kind='count')
方法1:
seaborn.countplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, orient=None, color=None, palette=None, saturation=0.75, dodge=True, ax=None, **kwargs)
方法2:
sns.catplot(x="species", kind="count", data=iris)
三.分布图
包括单变量核密度曲线,直方图,双变量多变量的联合直方图,和密度图
1.单分布
(1)distpot
方法:
seaborn.distplot(a, bins=None, hist=True, kde=True, rug=False, fit=None, hist_kws=None, kde_kws=None, rug_kws=None, fit_kws=None, color=None, vertical=False, norm_hist=False, axlabel=None, label=None, ax=None)
- 设置
kde=False则可以只绘制直方图,或者hist=False只绘制核密度估计图
举例:
sns.distplot(iris["sepal_length"])
(2)kdeplot
方法:
seaborn.kdeplot(data, data2=None, shade=False, vertical=False, kernel='gau', bw='scott', gridsize=100, cut=3, clip=None, legend=True, cumulative=False, shade_lowest=True, cbar=False, cbar_ax=None, cbar_kws=None, ax=None, **kwargs)
kdeplot可以专门用于绘制核密度估计图,其效果和distplot(hist=False)一致,但kdeplot拥有更多的自定义设置
举例:
sns.kdeplot(iris["sepal_length"])
2.双分布
(1)jointplot二元变量分布图
方法:
seaborn.jointplot(x, y, data=None, kind='scatter', stat_func=None, color=None, height=6, ratio=5, space=0.2, dropna=True, xlim=None, ylim=None, joint_kws=None, marginal_kws=None, annot_kws=None, **kwargs)
jointplot并不是一个 Figure-level 接口,但其支持kind=参数指定绘制出不同样式的分布图。例如,绘制出核密度估计对比图 kind = 'kde'。- kind='hex'绘制六边形计数图
- kind='reg'绘制回归拟合图
举例:
例如,我们探寻 sepal_length 和 sepal_width 二元特征变量之间的关系。
sns.jointplot(x="sepal_length", y="sepal_width", data=iris)
(2)pairpot
支持将数据集中的特征变量两两对比绘图,默认情况下,对角线上是单变量分布图,而其他是二元变量分布图
方法:
seaborn.pairplot(data, hue=None, hue_order=None, palette=None, vars=None, x_vars=None, y_vars=None, kind='scatter', diag_kind='auto', markers=None, height=2.5, aspect=1, dropna=True, plot_kws=None, diag_kws=None, grid_kws=None, size=None)
举例:
sns.pairplot(iris, hue="species")
(3)rugplot
方法:
seaborn.rugplot(a, height=0.05, axis='x', ax=None, **kwargs)
四.回归图
回归图只要探讨两连续数值变量的变化趋势情况,绘制x-y的散点图和回归曲线。
1.lmplot
方法:
seaborn.lmplot(x, y, data, hue=None, col=None, row=None, palette=None, col_wrap=None, height=5, aspect=1, markers='o', sharex=True, sharey=True, hue_order=None, col_order=None, row_order=None, legend=True, legend_out=True, x_estimator=None, x_bins=None, x_ci='ci', scatter=True, fit_reg=True, ci=95, n_boot=1000, units=None, order=1, logistic=False, lowess=False, robust=False, logx=False, x_partial=None, y_partial=None, truncate=False, x_jitter=None, y_jitter=None, scatter_kws=None, line_kws=None, size=None)
- seaborn.lmplot
lmplot同样是用于绘制回归图,但lmplot支持引入第三维度进行对比,例如我们设置hue="species"。
举例:
sns.lmplot(x="sepal_length", y="sepal_width", hue="species", data=iris)
2.regplot
方法:用线性回归模型对数据做拟合
seaborn.regplot(x, y, data=None, x_estimator=None, x_bins=None, x_ci='ci', scatter=True, fit_reg=True, ci=95, n_boot=1000, units=None, order=1, logistic=False, lowess=False, robust=False, logx=False, x_partial=None, y_partial=None, truncate=False, dropna=True, x_jitter=None, y_jitter=None, label=None, color=None, marker='o', scatter_kws=None, line_kws=None, ax=None)
- seaborn.regplot
regplot绘制回归图时,只需要指定自变量和因变量即可,regplot会自动完成线性回归拟合。
举例:
sns.regplot(x="sepal_length", y="sepal_width", data=iris)
3.residplot
方法:展示线性回归模型拟合后各点对应的残值
seaborn.residplot(x, y, data=None, lowess=False, x_partial=None, y_partial=None, order=1, robust=False, dropna=True, label=None, color=None, scatter_kws=None, line_kws=None, ax=None)
举例:可以对以年为单位的地震记录作线性回归拟合。以下两张图分别对应一阶线性回归拟合、拟合后残值分布情况图。
plt.figure(figsize=(12,6))
plt.subplot(121)
sns.regplot(x="Year", y="ID",
data=temp,order=1) # default by 1plt.ylabel(' ')
plt.title('Regression fit of earthquake records by year,order = 1') plt.subplot(122)
sns.residplot(x="Year", y="ID",
data=temp)
plt.ylabel(' ')
plt.title('Residual plot when using a simplt regression
model,order=1')
plt.show()
五.矩阵图
1.热力图heatmap
方法:用颜色矩阵去显示数据在两个维度下的度量值
seaborn.heatmap(data, vmin=None, vmax=None, cmap=None, center=None, robust=False, annot=None, fmt='.2g', annot_kws=None, linewidths=0, linecolor='white', cbar=True, cbar_kws=None, cbar_ax=None, square=False, xticklabels='auto', yticklabels='auto', mask=None, ax=None, **kwargs)
- 热力图在某些场景下非常实用,例如绘制出变量相关性系数热力图。
举例:
import numpy as np sns.heatmap(np.random.rand(10, 10))
2.聚类图clustermap
方法:
seaborn.clustermap(data, pivot_kws=None, method='average', metric='euclidean', z_score=None, standard_scale=None, figsize=None, cbar_kws=None, row_cluster=True, col_cluster=True, row_linkage=None, col_linkage=None, row_colors=None, col_colors=None, mask=None, **kwargs)
- 除此之外,
clustermap支持绘制层次聚类结构图。如下所示,我们先去掉原数据集中最后一个目标列,传入特征数据即可。当然,你需要对层次聚类有所了解,否则很难看明白图像多表述的含义。
举例:
iris.pop("species")
sns.clustermap(iris)
六.时间序列图
1.时间序列图tsplot
用时间维度序列去展现数据的不确定性
2.网格时序图plot_ts_d , plot_ts_m
七.多绘图网格
1.小平面网格
1.1 FaceGrid
1.2 FacetGrid.map
1.3 FacetGrid.map_dataframe
2.配对网格
2.1 PairGrid
2.2 PairGrid.map
2.3 PairGrid.map_diag
2.4 PairGrid.map_offdiag
2.5 PairGrid.map_lower
2.6 PairGrid.map_upper
3.联合网格
3.1 JointGrid
3.2 JointGrid.plot
3.3 JointGrid.plot_joint
3.4 JointGrid.plot_marginals
参考文献:
【2】5种方法教你用Python玩转histogram直方图
【4】python可视化进阶---seaborn1.7 分类数据可视化 - 统计图 barplot() / countplot() / pointplot()
【5】seaborn官网
seaborn(2)---画分类图/分布图/回归图/矩阵图的更多相关文章
- Python图表数据可视化Seaborn:2. 分类数据可视化-分类散点图|分布图(箱型图|小提琴图|LV图表)|统计图(柱状图|折线图)
1. 分类数据可视化 - 分类散点图 stripplot( ) / swarmplot( ) sns.stripplot(x="day",y="total_bill&qu ...
- Matplotlib学习---用seaborn画矩阵图(pair plot)
矩阵图非常有用,人们经常用它来查看多个变量之间的联系. 下面用著名的鸢尾花数据来画一个矩阵图.从sklearn导入鸢尾花数据,然后将其转换成pandas的DataFrame类型,最后用seaborn画 ...
- Python统计分析可视化库seaborn(相关性图,变量分布图,箱线图等等)
Visualization of seaborn seaborn[1]是一个建立在matplot之上,可用于制作丰富和非常具有吸引力统计图形的Python库.Seaborn库旨在将可视化作为探索和理 ...
- Python图表数据可视化Seaborn:1. 风格| 分布数据可视化-直方图| 密度图| 散点图
conda install seaborn 是安装到jupyter那个环境的 1. 整体风格设置 对图表整体颜色.比例等进行风格设置,包括颜色色板等调用系统风格进行数据可视化 set() / se ...
- Python图表数据可视化Seaborn:3. 线性关系数据| 时间线图表| 热图
1. 线性关系数据可视化 lmplot( ) import numpy as np import pandas as pd import matplotlib.pyplot as plt import ...
- seaborn学习笔记(四):箱型图、小提琴图
html { font-family: sans-serif; -ms-text-size-adjust: 100%; -webkit-text-size-adjust: 100% } body { ...
- 【R作图】lattice包,画多个分布柱形图,hist图纵轴转换为百分比
一开始用lattice包,感觉在多元数据的可视化方面,确实做得非常好.各种函数,可以实现任何想要实现的展示. barchart(y ~ x) y对x的直方图 bwplot(y ~ x) 盒形图 den ...
- haploview画出所有SNP的LD关系图
有时候我们想画出所有SNP的LD关系图,则需要在命令行添加“-skipcheck”命令行,如下所示: java -jar Haploview.jar -skipcheck -n -pedfile 80 ...
- 还能这么玩?用VsCode画类图、流程图、时序图、状态图...不要太爽!
文章每周持续更新,各位的「三连」是对我最大的肯定.可以微信搜索公众号「 后端技术学堂 」第一时间阅读(一般比博客早更新一到两篇) 软件设计中,有好几种图需要画,比如流程图.类图.组件图等,我知道大部分 ...
随机推荐
- Javascript Asynchronous Investigation
介绍 同步任务:在主线程上排队执行的任务,只有前一个任务执行完毕,才能执行后一个任务: 异步任务:不进入主线程,而进入任务队列中的任务,只有任务队列通知主线程,某个异步任务可以执行了,这个任务才会进入 ...
- Gamma阶段第八次scrum meeting
每日任务内容 队员 昨日完成任务 明日要完成的任务 张圆宁 #91 用户体验与优化https://github.com/rRetr0Git/rateMyCourse/issues/91(持续完成) # ...
- Java操作Hive
Hadoop版本:hadoop-2.9.2.tar.gz,Hive版本:apache-hive-2.3.6-src.tar.gz,安装Hive可查看:CentOS安装Hive 保证Hive以正确启动h ...
- sqlcode与sqlerrm的区别
sqlCode:是数据库操作的返回码,其中0--成功:-1--失败:100--没有检索到数据. sqlerrm:是数返回指定错误代码的错误信息. 在一个内在的异常中,SQLCODE返回Oracle错误 ...
- Windows下安装 Linux 下vim编辑器
Windows下安装vim编辑器 下载传送门 https://vim.en.softonic.com/download# 开始安装 这是下载后的可执行文件 双击(或单击)运行软件,选择同意继续进行安装 ...
- JSON -------- json与字符串之间的转换
JSON 最常见的用法,从web服务器上读取JSON数据(作为文件或HttpRequers),将JSON 转换为JavaScript ,然后在网页中使用 1.JSON文本转换为JavaScript 对 ...
- react 父组件调用子组件方法、子组件调用父组件方法
我们闲话不多说,直接上代码 // 父组件 import React, {Component} from 'react'; class Parents extends Component { const ...
- c++中如何判断sqlite表是否存在
在项目中遇到需要判断sqlite数据库中某个表是否存在,上网搜索一些资料后,解决了问题,如下: 首先,在每个sqlite数据库中,都有一个名为sqlite_master的表,它定义了数据库的模式,它的 ...
- 【Python爬虫案例学习】Python爬取天涯论坛评论
用到的包有requests - BeautSoup 我爬的是天涯论坛的财经论坛:'http://bbs.tianya.cn/list.jsp?item=develop' 它里面的其中的一个帖子的URL ...
- linux中awk工具的使用(转)
add by zhj: awk很强大,它是一个简单的编程语言,国外有本专门的书介绍它的用法.<effective awk programming>,它支持整型,字符串型,数组,变量在使用前 ...