ITPub博客

首页 > IT基础架构 > > Seaborn_Tutorial_Distribution_plots:[1]jointplot

Seaborn_Tutorial_Distribution_plots:[1]jointplot

作者:格伯纳 时间:2020-06-01 13:31:43 0 删除 编辑

seaborn.jointplot(x, y, data=None, kind='scatter', stat_func=<function pearsonr>, color=None, size=6, ratio=5, space=0.2, dropna=True, xlim=None, ylim=None, joint_kws=None,marginal_kws=None, annot_kws=None, **kwargs)

code for ipython notebook pleace click the github link below.

使用双变量和单变量图绘制两个变量的图。

Parameters:

x, y : 字符串或向量

数据中的变量的名称。

data : DataFrame,可选

DataFrame,当x和y是变量名称。

kind : { “scatter” | “reg” | “resid” | “kde” | “hex” }, 可选

绘制图的种类。

stat_func : callable或None,可选

用于计算关系的统计量并注释绘图的函数。 应该将x和y映射到单个值或元组。 如果不想注释绘图,请设置为“None”。

color : matplotlib颜色,可选

用于绘制元素的颜色。

size : 数字,可选

图的大小(正方形)。

ratio : 数字,可选

横轴尺寸与边缘轴高度的比率。

space : 数字,可选

横轴和边缘轴之间的空间

dropna : bool,可选

如果为True,则删除x和y中缺失的观测值。

{x, y}lim :两元组,可选

轴在绘图前设置的限制。

{joint, marginal, annot}_kws : dicts,可选

图组件的其他关键字参数。

kwargs : 键,值配对

附加的关键字参数传递给用于在联合轴上绘制绘图的函数,取代joint_kws字典中的项目。

Returns:

grid : JointGrid

JointGrid 对象及绘图

In[1]

%matplotlib inline
import numpy as np
import pandas as pd
import seaborn as sns
from scipy.stats import spearmanr
sns.set(style="white", color_codes=True)

设置白色为画图基准颜色

In[2]

trade = pd.read_csv('trade.csv')

读取数据

In[3]

trade.head()

查看数据前5行

In[4]

g = sns.jointplot(x="k1", y="k2", data=trade)

对k1和k2变量绘制带有边际直方图的散点图:

添加回归和核密度拟合:

In[5]

g = sns.jointplot(x="k1", y="k2", data=trade, kind="reg")

也可以使用六边形箱的联合直方图替换散点图:

In[6]

g = sns.jointplot(x="k1", y="k2", data=trade, kind="hex")

用密度估计值替换散点图和直方图,并用边界轴对齐边缘轴:

In[7]

g = sns.jointplot(x="k1", y="k2", data=trade, kind="kde", space=, color="g")

对注释使用不同的统计信息:

In[8]

g = sns.jointplot(x="k3", y="k4", data=trade, stat_func=spearmanr, color="m")

绘制散点图,然后添加一个联合密度估计:

In[9]

g = sns.jointplot(x="k3", y="k4", data=trade, stat_func=spearmanr,
                  color="m").plot_joint(sns.kdeplot, zorder=, n_levels=6)

直接传递向量而不使用Pandas,然后命名轴:

In[10]

x, y = np.random.randn(2, 300)
g = sns.jointplot(x, y, kind="hex", stat_func=None).set_axis_labels("x", "y")

将关键字参数传递给下面的图:

In[11]

g = sns.jointplot(x="k3", y="k4", data=trade, stat_func=spearmanr,
                  color="m", marginal_kws=dict(bins=15, rug=True),
                  annot_kws=dict(stat="r"), s=40, edgecolor="w", linewidth=1)

References

1.Hourout/seaborn.tutorial

2.seaborn.jointplot - seaborn 0.7.1 documentation

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/31509949/viewspace-3159869/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
管理员

注册时间:2018-03-30

  • 博文量
    2383
  • 访问量
    984352