二.分类图

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)
  • seaborn.distplot

  • 设置 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 拥有更多的自定义设置
  • seaborn.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)
  • seaborn.jointplot

  • 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)
  • 热力图在某些场景下非常实用,例如绘制出变量相关性系数热力图。
  • seaborn.heatmap

举例:

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 支持绘制层次聚类结构图。如下所示,我们先去掉原数据集中最后一个目标列,传入特征数据即可。当然,你需要对层次聚类有所了解,否则很难看明白图像多表述的含义。
  • seaborn.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

参考文献:

【1】Python学习笔记——数据分析之Seaborn绘图

【2】5种方法教你用Python玩转histogram直方图

【3】机器学习开放课程:二、使用Python可视化数据

【4】python可视化进阶---seaborn1.7 分类数据可视化 - 统计图 barplot() / countplot() / pointplot()

【5】seaborn官网

【6】Seaborn 数据可视化基础教程

seaborn(2)---画分类图/分布图/回归图/矩阵图的更多相关文章

  1. Python图表数据可视化Seaborn:2. 分类数据可视化-分类散点图|分布图(箱型图|小提琴图|LV图表)|统计图(柱状图|折线图)

    1. 分类数据可视化 - 分类散点图 stripplot( ) / swarmplot( ) sns.stripplot(x="day",y="total_bill&qu ...

  2. Matplotlib学习---用seaborn画矩阵图(pair plot)

    矩阵图非常有用,人们经常用它来查看多个变量之间的联系. 下面用著名的鸢尾花数据来画一个矩阵图.从sklearn导入鸢尾花数据,然后将其转换成pandas的DataFrame类型,最后用seaborn画 ...

  3. Python统计分析可视化库seaborn(相关性图,变量分布图,箱线图等等)

    Visualization of seaborn  seaborn[1]是一个建立在matplot之上,可用于制作丰富和非常具有吸引力统计图形的Python库.Seaborn库旨在将可视化作为探索和理 ...

  4. Python图表数据可视化Seaborn:1. 风格| 分布数据可视化-直方图| 密度图| 散点图

    conda  install seaborn  是安装到jupyter那个环境的 1. 整体风格设置 对图表整体颜色.比例等进行风格设置,包括颜色色板等调用系统风格进行数据可视化 set() / se ...

  5. Python图表数据可视化Seaborn:3. 线性关系数据| 时间线图表| 热图

    1. 线性关系数据可视化 lmplot( ) import numpy as np import pandas as pd import matplotlib.pyplot as plt import ...

  6. seaborn学习笔记(四):箱型图、小提琴图

    html { font-family: sans-serif; -ms-text-size-adjust: 100%; -webkit-text-size-adjust: 100% } body { ...

  7. 【R作图】lattice包,画多个分布柱形图,hist图纵轴转换为百分比

    一开始用lattice包,感觉在多元数据的可视化方面,确实做得非常好.各种函数,可以实现任何想要实现的展示. barchart(y ~ x) y对x的直方图 bwplot(y ~ x) 盒形图 den ...

  8. haploview画出所有SNP的LD关系图

    有时候我们想画出所有SNP的LD关系图,则需要在命令行添加“-skipcheck”命令行,如下所示: java -jar Haploview.jar -skipcheck -n -pedfile 80 ...

  9. 还能这么玩?用VsCode画类图、流程图、时序图、状态图...不要太爽!

    文章每周持续更新,各位的「三连」是对我最大的肯定.可以微信搜索公众号「 后端技术学堂 」第一时间阅读(一般比博客早更新一到两篇) 软件设计中,有好几种图需要画,比如流程图.类图.组件图等,我知道大部分 ...

随机推荐

  1. tomcat Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986

      1.情景展示 tomcat 日志时不时会报出如下异常信息,到底是怎么回事? java.lang.IllegalArgumentException: Invalid character found ...

  2. 【IntelliJ IDEA学习之五】IntelliJ IDEA 搭建项目

    版本:IntelliJIDEA2018.1.4 一.同一窗口展示多个应用(弊端:耗内存) idea没有eclipse workspace的概念,如果想在同一窗口显示多个应用,可以按照如下方式来做:1. ...

  3. 三个基于.net的浏览器内核使用的比较

    最近做模拟登陆发帖相关的项目 分别尝试了基于IE .NET自带的 webbrowser 和 基于WebKit 的WebKit.NET和openWebkitSharp 最开始肯定是用的.NET自带的we ...

  4. rpm续

    一.安装源码包 安装源码包通常须要一下三步: (1) ./configure. 这步可以定制功能,加上相应 的选项即可,具体有什么选项可以通过命令./configure help来查看.这一步会 自动 ...

  5. Kafka支持单集群20万分区

    Kafka支持单集群20万分区 之前网上关于确定Kafka分区数的博客多多少少都源自于饶军大神的文章,如今他带来了这方面的第二篇文章,特此翻译一下,记录一下其中的要点. 原贴地址: https://w ...

  6. Logstash测试的时候,报Error occurred during initialization of VM,Could not reserve enough space for object heap

    今天配置Logstash的时候,启动输入logstash ‐e 'input { stdin { } } output { stdout {} }'就开始报错了,Error occurred duri ...

  7. SQLServer --------- 将sql脚本文件导入数据库

    创建数据库方法有两种 第一种通过图形化的操作界面 第二种通过 sql 语句 sql server 如何执行.sql 文件,的原理就是执行sql语句进行创建 打开数据库后找到   最左侧文件 找到需要执 ...

  8. JMeter分布式测试环境搭建(禁用SSL)

    JMeter分布式环境,一台Master,一到多台Slave,Master和Slave可以是同一台机器. 前提条件: 所有机器,包括master和slave的机器: 1.运行相同版本的JMeter 2 ...

  9. 『Andrew and Chemistry 树同构』

    Andrew and Chemistry Description During the chemistry lesson Andrew learned that the saturated hydro ...

  10. GoF的23种设计模式之行为型模式的特点和分类(1)

    行为型模式用于描述程序在运行时复杂的流程控制,即描述多个类或对象之间怎样相互协作共同完成单个对象都无法单独完成的任务,它涉及算法与对象间职责的分配. 行为型模式分为类行为模式和对象行为模式,前者采用继 ...