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画类图、流程图、时序图、状态图...不要太爽!
文章每周持续更新,各位的「三连」是对我最大的肯定.可以微信搜索公众号「 后端技术学堂 」第一时间阅读(一般比博客早更新一到两篇) 软件设计中,有好几种图需要画,比如流程图.类图.组件图等,我知道大部分 ...
随机推荐
- c# json序列化不包括某列
.[Newtonsoft.Json.JsonIgnore]特性:使用Newtonsoft.Json序列化时字段不会被序列化. .[System.Web.Script.Serialization.Scr ...
- Redis哨兵、复制、集群的设计原理与区别
一 前言 谈到Redis服务器的高可用,如何保证备份的机器是原始服务器的完整备份呢?这时候就需要哨兵和复制. 哨兵(Sentinel):可以管理多个Redis服务器,它提供了监控,提醒以及自动的故障转 ...
- Appium 滑动踩坑记
前言 对于不同java-client版本,很多的API已经产生大的变化,所以一些API大家会发现已经失效或者使用方式发生了变化,滑动就是其中一项,这篇文章对滑动在不同的java-client版本以及不 ...
- linux 手动源码安装lnmp(亲测)
linux 手动源码安装lnmp笔记(亲测)<pre>先安装这2个yum install gccyum install g++</pre><pre>先在linux ...
- 在Windows 10中禁用自动文件夹类型发现
点击下载注册表文件:https://files.cnblogs.com/files/Music/win10_automatic_folder_type_discovery.zip 已知Windows ...
- GoF的23种设计模式之结构型模式的特点和分类
结构型模式描述如何将类或对象按某种布局组成更大的结构.它分为类结构型模式和对象结构型模式,前者采用继承机制来组织接口和类,后者釆用组合或聚合来组合对象. 由于组合关系或聚合关系比继承关系耦合度低,满足 ...
- 【LeetCode】387. First Unique Character in a String
Difficulty:easy More:[目录]LeetCode Java实现 Description https://leetcode.com/problems/first-unique-cha ...
- 显示 Uncaught TypeError: Cannot read property 'dialog' of undefined”的错误解决方法
最近在做一个基于easyUI的列表,新增功能的弹出框是以这样的方式: 运行测试的时候,报了这一堆的错误Uncaught TypeError: Cannot read property 'dialog' ...
- c++打印实心菱形,空心三角形,十字星,空心正方形,实心平行四边形
今天翻资料的时候,无意间发现了一个文件,是刚接触编程的时候用c++写的一段程序,我称之为"图形打印机",想着把所有图形都打印出来,后来发现其实每种图形的代码都是一个思路,就不想做重 ...
- 【翻译】在TypeScript中,Extends和Implements一个抽象类有什么不同
我们知道在TypeScript中一个类既可以被implement也可以被extends,有一些C#或java基础的同学可能会对此感到困惑,因为在上述两个面向对象的语言里面只有接口可以被implemen ...