散点分布图

综合表示散点图和直方分布图。

Jointplot()

绘制二变量或单变量的图形,底层是JointGrid()。

sns.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,
)
Docstring:
Draw a plot of two variables with bivariate and univariate graphs. This function provides a convenient interface to the :class:`JointGrid`
class, with several canned plot kinds. This is intended to be a fairly
lightweight wrapper; if you need more flexibility, you should use
:class:`JointGrid` directly. Parameters
----------
x, y : strings or vectors
Data or names of variables in ``data``.
data : DataFrame, optional
DataFrame when ``x`` and ``y`` are variable names.
kind : { "scatter" | "reg" | "resid" | "kde" | "hex" }, optional
Kind of plot to draw.
stat_func : callable or None, optional
*Deprecated*
color : matplotlib color, optional
Color used for the plot elements.
height : numeric, optional
Size of the figure (it will be square).
ratio : numeric, optional
Ratio of joint axes height to marginal axes height.
space : numeric, optional
Space between the joint and marginal axes
dropna : bool, optional
If True, remove observations that are missing from ``x`` and ``y``.
{x, y}lim : two-tuples, optional
Axis limits to set before plotting.
{joint, marginal, annot}_kws : dicts, optional
Additional keyword arguments for the plot components.
kwargs : key, value pairings
Additional keyword arguments are passed to the function used to
draw the plot on the joint Axes, superseding items in the
``joint_kws`` dictionary. Returns
-------
grid : :class:`JointGrid`
:class:`JointGrid` object with the plot on it. See Also
--------
JointGrid : The Grid class used for drawing this plot. Use it directly if
you need more flexibility.
#综合散点分布图-jointplot

#创建DataFrame数组
rs = np.random.RandomState(3)
df = pd.DataFrame(rs.randn(200,2), columns=['A','B']) #绘制综合散点分布图jointplot()
sns.jointplot(x=df['A'], y=df['B'], #设置x和y轴的数据
data=df, #设置数据
color='k',
s=50, edgecolor='w', linewidth=1, #散点大小、边缘线颜色和宽度(只针对scatter)
kind='scatter', #默认类型:“scatter”,其他有“reg”、“resid”、“kde”
space=0.2, #设置散点图和布局图的间距
height=8, #图表的大小(自动调整为正方形)
ratio=5, #散点图与布局图高度比率
stat_func= sci.pearsonr, #pearson相关系数
marginal_kws=dict(bins=15, rug=True)) #边际图的参数

sns.jointplot(x=df['A'], y=df['B'],
data=df,
color='k',
kind='reg', #reg添加线性回归线
height=8,
ratio=5,
stat_func= sci.pearsonr,
marginal_kws=dict(bins=15, rug=True))

sns.jointplot(x=df['A'], y=df['B'],
data=df,
color='k',
kind='resid', #resid
height=8,
ratio=5,
marginal_kws=dict(bins=15, rug=True))

sns.jointplot(x=df['A'], y=df['B'],
data=df,
color='k',
kind='kde', #kde密度图
height=8,
ratio=5)

sns.jointplot(x=df['A'], y=df['B'],
data=df,
color='k',
kind='hex', #hex蜂窝图(六角形)
height=8,
ratio=5)

g = sns.jointplot(x=df['A'], y=df['B'],
data=df,
color='k',
kind='kde', #kde密度图
height=8,
ratio=5,
shade_lowest=False) #添加散点图(c-->颜色,s-->大小)
g.plot_joint(plt.scatter, c='w', s=10, linewidth=1, marker='+')

JointGrid()

创建图形网格,用于绘制二变量或单变量的图形,作用和Jointplot()一样,不过比Jointplot()更灵活。

sns.JointGrid(
x,
y,
data=None,
height=6,
ratio=5,
space=0.2,
dropna=True,
xlim=None,
ylim=None,
size=None,
)
Docstring: Grid for drawing a bivariate plot with marginal univariate plots.
Init docstring:
Set up the grid of subplots. Parameters
----------
x, y : strings or vectors
Data or names of variables in ``data``.
data : DataFrame, optional
DataFrame when ``x`` and ``y`` are variable names.
height : numeric
Size of each side of the figure in inches (it will be square).
ratio : numeric
Ratio of joint axes size to marginal axes height.
space : numeric, optional
Space between the joint and marginal axes
dropna : bool, optional
If True, remove observations that are missing from `x` and `y`.
{x, y}lim : two-tuples, optional
Axis limits to set before plotting. See Also
--------
jointplot : High-level interface for drawing bivariate plots with
several different default plot kinds.
#设置风格
sns.set_style('white')
#导入数据
tip_datas = sns.load_dataset('tips', data_home='seaborn-data') #绘制绘图网格,包含三部分:一个主绘图区域,两个边际绘图区域
g = sns.JointGrid(x='total_bill', y='tip', data=tip_datas) #主绘图区域:散点图
g.plot_joint(plt.scatter, color='m', edgecolor='w', alpha=.3) #边际绘图区域:x和y轴
g.ax_marg_x.hist(tip_datas['total_bill'], color='b', alpha=.3)
g.ax_marg_y.hist(tip_datas['tip'], color='r', alpha=.3,
orientation='horizontal') #相关系数标签
from scipy import stats
g.annotate(stats.pearsonr) #绘制表格线
plt.grid(linestyle='--')

g = sns.JointGrid(x='total_bill', y='tip', data=tip_datas)
g = g.plot_joint(plt.scatter, color='g', s=40, edgecolor='white')
plt.grid(linestyle='--')
#两边边际图用统一函数设置统一风格
g.plot_marginals(sns.distplot, kde=True, color='g')

g = sns.JointGrid(x='total_bill', y='tip', data=tip_datas)
#主绘图设置密度图
g = g.plot_joint(sns.kdeplot, cmap='Reds_r')
plt.grid(linestyle='--')
#两边边际图用统一函数设置统一风格
g.plot_marginals(sns.distplot, kde=True, color='g')

Pairplot()

用于数据集的相关性图形绘制,如:矩阵图,底层是PairGrid()。

sns.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,
)
Docstring:
Plot pairwise relationships in a dataset. By default, this function will create a grid of Axes such that each
variable in ``data`` will by shared in the y-axis across a single row and
in the x-axis across a single column. The diagonal Axes are treated
differently, drawing a plot to show the univariate distribution of the data
for the variable in that column. It is also possible to show a subset of variables or plot different
variables on the rows and columns. This is a high-level interface for :class:`PairGrid` that is intended to
make it easy to draw a few common styles. You should use :class:`PairGrid`
directly if you need more flexibility. Parameters
----------
data : DataFrame
Tidy (long-form) dataframe where each column is a variable and
each row is an observation.
hue : string (variable name), optional
Variable in ``data`` to map plot aspects to different colors.
hue_order : list of strings
Order for the levels of the hue variable in the palette
palette : dict or seaborn color palette
Set of colors for mapping the ``hue`` variable. If a dict, keys
should be values in the ``hue`` variable.
vars : list of variable names, optional
Variables within ``data`` to use, otherwise use every column with
a numeric datatype.
{x, y}_vars : lists of variable names, optional
Variables within ``data`` to use separately for the rows and
columns of the figure; i.e. to make a non-square plot.
kind : {'scatter', 'reg'}, optional
Kind of plot for the non-identity relationships.
diag_kind : {'auto', 'hist', 'kde'}, optional
Kind of plot for the diagonal subplots. The default depends on whether
``"hue"`` is used or not.
markers : single matplotlib marker code or list, optional
Either the marker to use for all datapoints or a list of markers with
a length the same as the number of levels in the hue variable so that
differently colored points will also have different scatterplot
markers.
height : scalar, optional
Height (in inches) of each facet.
aspect : scalar, optional
Aspect * height gives the width (in inches) of each facet.
dropna : boolean, optional
Drop missing values from the data before plotting.
{plot, diag, grid}_kws : dicts, optional
Dictionaries of keyword arguments. Returns
-------
grid : PairGrid
Returns the underlying ``PairGrid`` instance for further tweaking. See Also
--------
PairGrid : Subplot grid for more flexible plotting of pairwise
relationships.
#导入鸢尾花数据
i_datas = sns.load_dataset('iris', data_home='seaborn-data')
i_datas #矩阵散点图
sns.pairplot(i_datas,
kind='scatter', #图形类型(散点图:scatter, 回归分布图:reg)
diag_kind='hist', #对角线的图形类型(直方图:hist, 密度图:kde)
hue='species', #按照某一字段分类
palette='husl', #设置调色板
markers=['o','s','D'], #设置点样式
height=2) #设置图标大小

#矩阵回归分析图
sns.pairplot(i_datas,
kind='reg', #图形类型(散点图:scatter, 回归分布图:reg)
diag_kind='kde', #对角线的图形类型(直方图:hist, 密度图:kde)
hue='species', #按照某一字段分类
palette='husl', #设置调色板
markers=['o','s','D'], #设置点样式
height=2) #设置图标大小

#局部变量选择,vars
g = sns.pairplot(i_datas, vars=['sepal_width', 'sepal_length'],
kind='reg', diag_kind='kde',
hue='species', palette='husl')

#综合参数设置
sns.pairplot(i_datas, diag_kind='kde', markers='+', hue='species',
#散点图的参数
plot_kws=dict(s=50, edgecolor='b', linewidth=1),
#对角线图的参数
diag_kws=dict(shade=True))

PairGrid()

用于数据集的相关性图形绘制,如:矩阵图。功能比Pairplot()更加灵活。

sns.PairGrid(
data,
hue=None,
hue_order=None,
palette=None,
hue_kws=None,
vars=None,
x_vars=None,
y_vars=None,
diag_sharey=True,
height=2.5,
aspect=1,
despine=True,
dropna=True,
size=None,
)
Docstring:
Subplot grid for plotting pairwise relationships in a dataset. This class maps each variable in a dataset onto a column and row in a
grid of multiple axes. Different axes-level plotting functions can be
used to draw bivariate plots in the upper and lower triangles, and the
the marginal distribution of each variable can be shown on the diagonal. It can also represent an additional level of conditionalization with the
``hue`` parameter, which plots different subets of data in different
colors. This uses color to resolve elements on a third dimension, but
only draws subsets on top of each other and will not tailor the ``hue``
parameter for the specific visualization the way that axes-level functions
that accept ``hue`` will. See the :ref:`tutorial <grid_tutorial>` for more information.
Init docstring:
Initialize the plot figure and PairGrid object. Parameters
----------
data : DataFrame
Tidy (long-form) dataframe where each column is a variable and
each row is an observation.
hue : string (variable name), optional
Variable in ``data`` to map plot aspects to different colors.
hue_order : list of strings
Order for the levels of the hue variable in the palette
palette : dict or seaborn color palette
Set of colors for mapping the ``hue`` variable. If a dict, keys
should be values in the ``hue`` variable.
hue_kws : dictionary of param -> list of values mapping
Other keyword arguments to insert into the plotting call to let
other plot attributes vary across levels of the hue variable (e.g.
the markers in a scatterplot).
vars : list of variable names, optional
Variables within ``data`` to use, otherwise use every column with
a numeric datatype.
{x, y}_vars : lists of variable names, optional
Variables within ``data`` to use separately for the rows and
columns of the figure; i.e. to make a non-square plot.
height : scalar, optional
Height (in inches) of each facet.
aspect : scalar, optional
Aspect * height gives the width (in inches) of each facet.
despine : boolean, optional
Remove the top and right spines from the plots.
dropna : boolean, optional
Drop missing values from the data before plotting. See Also
--------
pairplot : Easily drawing common uses of :class:`PairGrid`.
FacetGrid : Subplot grid for plotting conditional relationships.
#绘制四个参数vars的绘图网格(subplots)
g = sns.PairGrid(i_datas, hue='species', palette='hls',
vars=['sepal_length', 'sepal_width', 'petal_length', 'petal_width']) #对角线图形绘制
g.map_diag(plt.hist,
histtype='step', #可选:'bar'\ 'barstacked'\'step'\'stepfilled'
linewidth=1) #非对角线图形绘制
g.map_offdiag(plt.scatter, s=40, linewidth=1) #添加图例
g.add_legend()

g = sns.PairGrid(i_datas)

#主对角线图形
g.map_diag(sns.kdeplot) #上三角图形
g.map_upper(plt.scatter) #下三角图形
g.map_lower(sns.kdeplot, cmap='Blues_d')

Seaborn分布数据可视化---散点分布图的更多相关文章

  1. seaborn分布数据可视化:直方图|密度图|散点图

    系统自带的数据表格(存放在github上https://github.com/mwaskom/seaborn-data),使用时通过sns.load_dataset('表名称')即可,结果为一个Dat ...

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

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

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

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

  4. seaborn线性关系数据可视化:时间线图|热图|结构化图表可视化

    一.线性关系数据可视化lmplot( ) 表示对所统计的数据做散点图,并拟合一个一元线性回归关系. lmplot(x, y, data, hue=None, col=None, row=None, p ...

  5. seaborn分类数据可视化

    转载:https://cloud.tencent.com/developer/article/1178368 seaborn针对分类型的数据有专门的可视化函数,这些函数可大致分为三种: 分类数据散点图 ...

  6. seaborn分类数据可视化:散点图|箱型图|小提琴图|lv图|柱状图|折线图

    一.散点图stripplot( ) 与swarmplot() 1.分类散点图stripplot( ) 用法stripplot(x=None, y=None, hue=None, data=None, ...

  7. 用seaborn对数据可视化

    以下用sns作为seaborn的别名 1.seaborn整体布局设置 sns.set_syle()函数设置图的风格,传入的参数可以是"darkgrid", "whiteg ...

  8. Python Seaborn综合指南,成为数据可视化专家

    概述 Seaborn是Python流行的数据可视化库 Seaborn结合了美学和技术,这是数据科学项目中的两个关键要素 了解其Seaborn作原理以及使用它生成的不同的图表 介绍 一个精心设计的可视化 ...

  9. Seaborn数据可视化入门

    在本节学习中,我们使用Seaborn作为数据可视化的入门工具 Seaborn的官方网址如下:http://seaborn.pydata.org 一:definition Seaborn is a Py ...

  10. seaborn教程4——分类数据可视化

    https://segmentfault.com/a/1190000015310299 Seaborn学习大纲 seaborn的学习内容主要包含以下几个部分: 风格管理 绘图风格设置 颜色风格设置 绘 ...

随机推荐

  1. java数组实现的超市管理系统(控制台)

    说明:使用数组存储数据,针对用户功能1:增加用户2:删除用户3:修改用户:针对商品功能:1.显示所有商品2.修改商品信息3.添加商品信息4.删除商品信息5.查询商品信息 效果展示 ========== ...

  2. ASP.NET Core 选项

    目录 1,选项接口 2,注入配置与IOptions 3,IOptionsSnapshot 首先要了解 ASP.NET Core 中的配置,请点击这里了解:https://www.cnblogs.com ...

  3. 关闭mysql上锁的表/数据

    一.输入查询语句,查看是否有数据被上锁 select * from information_schema.innodb_trx; 取 trx_mysql_thread_id 字段值 kill < ...

  4. android 混淆规则作用,Android代码混淆详解

    一.混淆的意义 混淆代码并不是让代码无法被反编译,而是将代码中的类.方法.变量等信息进行重命名,把它们改成一些毫无意义的名字,同时也可以移除未被使用的类.方法.变量等. 所以直观的看,通过混淆可以提高 ...

  5. LLM 推理和应用 开源框架梳理

    之前对LLM 推理和应用了解不多,因此抽时间梳理了一下,我们从模型量化,模型推理,以及开发平台等三个层面来梳理分析. 模型量化 模型训练时为了进度,采用的32位浮点数,因此占用的空间较大,一些大的模型 ...

  6. linux下,使用nginx实现动静分离,访问图片报404

    一.需求描述 最近在开发一个微信小程序,由于微信小程序端代码包总大小限定在三四兆,所以有很多的图标资源就不能放在微信小程序中进行打包, 否则会超过微信的限制而无法打包.自己能够想到的最简单的办法就是将 ...

  7. 动态less 解决 vue main.js

    // 引入主题文件 // eslint-disable-next-line no-unused-expressions import('./theme/color/' + config.theme + ...

  8. Kotlin 快速遍历File及子目录筛选指定类型文件

    原文: Kotlin 快速遍历File及子目录筛选指定类型文件 - Stars-One的杂货小窝 在做文件相关的app,经常会遇到筛选某个文件夹下的符合条件的文件对象,且要包含子文件夹,之前一直是自己 ...

  9. cpprestsdk移植到mingw,项目上传至github

    如题 https://github.com/bbqz007/cpprestsdk4mingw 移植过程解决的问题,下面列出其中一些问题: 1. mingw对#pragma once支持不好. 须要在所 ...

  10. 关于C++ 多态实现技术的深度解析(vfptr,vftable)

    PS:要转载请注明出处,本人版权所有. PS: 这个只是基于<我自己>的理解, 如果和你的原则及想法相冲突,请谅解,勿喷. 前置说明   本文作为本人csdn blog的主站的备份.(Bl ...