From 757e6e0733a40af7e68e8315203b2bdcef49f48d Mon Sep 17 00:00:00 2001 From: Cancan <37414062+cancan233@users.noreply.github.com> Date: Mon, 22 Jul 2019 01:23:30 -0400 Subject: [PATCH] add 6.md zh-version --- docs/6.md | 175 +++++++++++++++++++++++------------------------------- 1 file changed, 73 insertions(+), 102 deletions(-) diff --git a/docs/6.md b/docs/6.md index 8f28a85..f0ba83f 100644 --- a/docs/6.md +++ b/docs/6.md @@ -1,282 +1,253 @@ -# Visualizing linear relationships +# 线性关系可视化 -Many datasets contain multiple quantitative variables, and the goal of an analysis is often to relate those variables to each other. We [previously discussed](distributions.html#distribution-tutorial) functions that can accomplish this by showing the joint distribution of two variables. It can be very helpful, though, to use statistical models to estimate a simple relationship between two noisy sets of observations. The functions discussed in this chapter will do so through the common framework of linear regression. +许多数据集包含多定量变量,并且分析的目的通常是将这些变量联系起来。我们[之前讨论](#/docs/5)可以通过显示两个变量相关性的来实现此目的的函数。但是,使用统计模型来估计两组噪声观察量之间的简单关系可能会非常有效。本章讨论的函数将通过线性回归的通用框架实现。 -In the spirit of Tukey, the regression plots in seaborn are primarily intended to add a visual guide that helps to emphasize patterns in a dataset during exploratory data analyses. That is to say that seaborn is not itself a package for statistical analysis. To obtain quantitative measures related to the fit of regression models, you should use [statsmodels](https://www.statsmodels.org/). The goal of seaborn, however, is to make exploring a dataset through visualization quick and easy, as doing so is just as (if not more) important than exploring a dataset through tables of statistics. +本着图凯(Tukey)精神,seaborn中的回归图主要用于添加视觉指南,以助于在探索性数据分析中强调存在于数据集的模式。换而言之,seaborn本身不是为统计分析而生。要获得与回归模型拟合相关定量度量,你应当使用 [statsmodels](https://www.statsmodels.org/). 然而,seaborn的目标是通过可视化快速简便地3探索数据集,因为这样做,如果说不上更,是与通过统计表探索数据集一样重要。 -```py +``` python import numpy as np import seaborn as sns import matplotlib.pyplot as plt - ``` -```py +``` python sns.set(color_codes=True) - ``` -```py +``` python tips = sns.load_dataset("tips") - ``` -## Functions to draw linear regression models +## 绘制线性回归模型的函数 -Two main functions in seaborn are used to visualize a linear relationship as determined through regression. These functions, [`regplot()`](../generated/seaborn.regplot.html#seaborn.regplot "seaborn.regplot") and [`lmplot()`](../generated/seaborn.lmplot.html#seaborn.lmplot "seaborn.lmplot") are closely related, and share much of their core functionality. It is important to understand the ways they differ, however, so that you can quickly choose the correct tool for particular job. +seaborn中两个主要函数主要用于显示回归确定的线性关系。这些函数,[`regplot()`](../ generated / seaborn.regplot.html#seaborn.regplot"seaborn.regplot")和[`lmplot()`](../ generated / seaborn.lmplot.html #seaborn.lmplot"seaborn.lmplot"), 之间密切关联,并且共享核心功能。但是,了解它们的不同之处非常重要,这样你就可以快速为特定工作选择正确的工具。 -In the simplest invocation, both functions draw a scatterplot of two variables, `x` and `y`, and then fit the regression model `y ~ x` and plot the resulting regression line and a 95% confidence interval for that regression: +在最简单的调用中,两个函数都绘制了两个变量,`x`和`y`,然后拟合回归模型`y~x`并绘制得到回归线和该回归的95%置信区间: -```py +```python sns.regplot(x="total_bill", y="tip", data=tips); - ``` ![http://seaborn.pydata.org/_images/regression_7_0.png](img/06f05fb132ef0dc7f9cca60a16b84f1a.jpg) -```py +```python sns.lmplot(x="total_bill", y="tip", data=tips); - ``` ![http://seaborn.pydata.org/_images/regression_8_0.png](img/ff165b205839381bf1fa11c2df3d176d.jpg) -You should note that the resulting plots are identical, except that the figure shapes are different. We will explain why this is shortly. For now, the other main difference to know about is that [`regplot()`](../generated/seaborn.regplot.html#seaborn.regplot "seaborn.regplot") accepts the `x` and `y` variables in a variety of formats including simple numpy arrays, pandas `Series` objects, or as references to variables in a pandas `DataFrame` object passed to `data`. In contrast, [`lmplot()`](../generated/seaborn.lmplot.html#seaborn.lmplot "seaborn.lmplot") has `data` as a required parameter and the `x` and `y` variables must be specified as strings. This data format is called “long-form” or [“tidy”](https://vita.had.co.nz/papers/tidy-data.pdf) data. Other than this input flexibility, [`regplot()`](../generated/seaborn.regplot.html#seaborn.regplot "seaborn.regplot") possesses a subset of [`lmplot()`](../generated/seaborn.lmplot.html#seaborn.lmplot "seaborn.lmplot")’s features, so we will demonstrate them using the latter. +你应当注意到,除了图形形状不同,两幅结果图是完全一致的。我们会在后面解释原因。目前,要了解的另一个主要区别是[`regplot()`](../ generated / seaborn.regplot.html#seaborn.regplot"seaborn.regplot")接受多种格式的`x`和`y`变量,包括简单的numpy数组,pandas `Series`对象,或者作为对传递给`data`的pandas `DataFrame`对象。相反,[`lmplot()`](../ generated / seaborn.lmplot.html#seaborn.lmplot"seaborn.lmplot")将`data`作为必须参数,`x`和`y`变量必须被指定为字符串。这种数据格式被称为"长格式"或["整齐"](https://vita.had.co.nz/papers/tidy-data.pdf)数据。 除了这种输入的灵活性之外,[`regplot()`](../ generated / seaborn.regplot.html#seaborn.regplot"seaborn.regplot")拥有[`lmplot()`](../ generated / seaborn.lmplot.html#seaborn.lmplot"seaborn.lmplot")一个子集的功能,所以我们将使用后者来演示它们。 -It’s possible to fit a linear regression when one of the variables takes discrete values, however, the simple scatterplot produced by this kind of dataset is often not optimal: +当其中一个变量采用离散值时,可以拟合线性回归。但是,这种数据集生成的简单散点图通常不是最优的: -```py +```python sns.lmplot(x="size", y="tip", data=tips); - ``` ![http://seaborn.pydata.org/_images/regression_10_0.png](img/18916d57b3e69c5de1769a7b26e0f713.jpg) -One option is to add some random noise (“jitter”) to the discrete values to make the distribution of those values more clear. Note that jitter is applied only to the scatterplot data and does not influence the regression line fit itself: +一种选择是向离散值添加随机噪声("抖动"),以使这些值分布更清晰。需要注意的是,抖动仅用于散点图数据,而不会影响回归线本身拟合: -```py +```python sns.lmplot(x="size", y="tip", data=tips, x_jitter=.05); - ``` ![http://seaborn.pydata.org/_images/regression_12_0.png](img/2e23cc65e61b2659c68ac3746b8ebad1.jpg) -A second option is to collapse over the observations in each discrete bin to plot an estimate of central tendency along with a confidence interval: +第二种选择是综合每个离散箱中的观测值,以绘制集中趋势的估计值和置信区间: -```py +```python sns.lmplot(x="size", y="tip", data=tips, x_estimator=np.mean); - ``` ![http://seaborn.pydata.org/_images/regression_14_0.png](img/4dda0f476dee5bc15c815a9403521409.jpg) -## Fitting different kinds of models +## 拟合不同模型 -The simple linear regression model used above is very simple to fit, however, it is not appropriate for some kinds of datasets. The [Anscombe’s quartet](https://en.wikipedia.org/wiki/Anscombe%27s_quartet) dataset shows a few examples where simple linear regression provides an identical estimate of a relationship where simple visual inspection clearly shows differences. For example, in the first case, the linear regression is a good model: +上面使用的简单线性回归模型非常容易拟合,但是它不适合某些类型的数据集。[Anscombe的四重奏](https://en.wikipedia.org/wiki/Anscombe%27s_quartet)数据集展示了一些实例,其中简单线性回归提供了相同的关系估计,然而简单的视觉检查清楚地显示了差异。例如,在第一种情况下,线性回归是一个很好的模型: -```py +```python anscombe = sns.load_dataset("anscombe") - ``` -```py +```python sns.lmplot(x="x", y="y", data=anscombe.query("dataset == 'I'"), ci=None, scatter_kws={"s": 80}); - ``` ![http://seaborn.pydata.org/_images/regression_17_0.png](img/7facbea48d8c72d5400863700e07aa18.jpg) -The linear relationship in the second dataset is the same, but the plot clearly shows that this is not a good model: +第二个数据集的线性关系是相同的,但是图表清楚地表明这并不是一个好的模型: -```py +```python sns.lmplot(x="x", y="y", data=anscombe.query("dataset == 'II'"), ci=None, scatter_kws={"s": 80}); - ``` ![http://seaborn.pydata.org/_images/regression_19_0.png](img/af2ff74dd015731938ea83ab029d73e7.jpg) -In the presence of these kind of higher-order relationships, [`lmplot()`](../generated/seaborn.lmplot.html#seaborn.lmplot "seaborn.lmplot") and [`regplot()`](../generated/seaborn.regplot.html#seaborn.regplot "seaborn.regplot") can fit a polynomial regression model to explore simple kinds of nonlinear trends in the dataset: +在这些存在高阶关系的情况下,[`regplot()`](../ generated / seaborn.regplot.html#seaborn.regplot"seaborn.regplot")和[`lmplot()`](./generated/seaborn.regplot.html#seaborn.regplot"seaborn.regplot")可以拟合多项式回归模型来探索数据集中的简单非线性趋势: -```py +```python sns.lmplot(x="x", y="y", data=anscombe.query("dataset == 'II'"), order=2, ci=None, scatter_kws={"s": 80}); - ``` ![http://seaborn.pydata.org/_images/regression_21_0.png](img/b2cde7454aa9f4cc76186d93a3cab208.jpg) -A different problem is posed by “outlier” observations that deviate for some reason other than the main relationship under study: +"离群值"观察引起的另一个问题是,除了研究中的主要关系之外,由于某种原因导致的偏离: -```py +```python sns.lmplot(x="x", y="y", data=anscombe.query("dataset == 'III'"), ci=None, scatter_kws={"s": 80}); - ``` ![http://seaborn.pydata.org/_images/regression_23_0.png](img/d9085f52d35beabc56a47c8326aee8cf.jpg) -In the presence of outliers, it can be useful to fit a robust regression, which uses a different loss function to downweight relatively large residuals: +在存在异常值的情况下,拟合稳健回归可能会很有用,该回归使用了一种不同的损失函数来降低相对较大的残差的权重: -```py +```python sns.lmplot(x="x", y="y", data=anscombe.query("dataset == 'III'"), robust=True, ci=None, scatter_kws={"s": 80}); - ``` ![http://seaborn.pydata.org/_images/regression_25_0.png](img/696b41cce47f6657e61372ff64381129.jpg) -When the `y` variable is binary, simple linear regression also “works” but provides implausible predictions: +当`y`变量是二进制时,简单线性回归也"有效",但提供了难以置信的预测: -```py +```python tips["big_tip"] = (tips.tip / tips.total_bill) > .15 sns.lmplot(x="total_bill", y="big_tip", data=tips, y_jitter=.03); - ``` ![http://seaborn.pydata.org/_images/regression_27_0.png](img/2b4711757bd351625d2244392491e1cf.jpg) -The solution in this case is to fit a logistic regression, such that the regression line shows the estimated probability of `y = 1` for a given value of `x`: +在这种情况下的解决方案是拟合逻辑回归,使得回归线对给定值`x`显示的估计概率`y=1`。 -```py +```python sns.lmplot(x="total_bill", y="big_tip", data=tips, logistic=True, y_jitter=.03); - ``` ![http://seaborn.pydata.org/_images/regression_29_0.png](img/afea667bcdb80a09c24a25f5d5d0bd82.jpg) -Note that the logistic regression estimate is considerably more computationally intensive (this is true of robust regression as well) than simple regression, and as the confidence interval around the regression line is computed using a bootstrap procedure, you may wish to turn this off for faster iteration (using `ci=None`). +请注意,逻辑回归估计比简单回归计算密集程度更高(稳健回归也是如此),并且由于回归线周围的置信区间是使用自举程度计算,你可能希望关闭它来达到更快的迭代(使用`ci=None`)。 -An altogether different approach is to fit a nonparametric regression using a [lowess smoother](https://en.wikipedia.org/wiki/Local_regression). This approach has the fewest assumptions, although it is computationally intensive and so currently confidence intervals are not computed at all: +一种完全不同的方法是使用[lowess smoother](https://en.wikipedia.org/wiki/Local_regression)拟合非参数回归。尽管它是计算密集型的,这种方法的假设最少,因此目前置信区间根本没有计算: -```py +```python sns.lmplot(x="total_bill", y="tip", data=tips, lowess=True); - ``` ![http://seaborn.pydata.org/_images/regression_31_0.png](img/640b99998425ffa57b452eca0b5e129b.jpg) -The [`residplot()`](../generated/seaborn.residplot.html#seaborn.residplot "seaborn.residplot") function can be a useful tool for checking whether the simple regression model is appropriate for a dataset. It fits and removes a simple linear regression and then plots the residual values for each observation. Ideally, these values should be randomly scattered around `y = 0`: +[`residplot()`](../generated/seaborn.residplot.html#seaborn.residplot "seaborn.residplot") 函数可以用作检查简单回归模型是否适合数据集的有效工具。它拟合并删除简单的线性回归,然后绘制每个观察值的残差值。理想情况下,这些值应随机散步在`y=0`周围: -```py +```python sns.residplot(x="x", y="y", data=anscombe.query("dataset == 'I'"), scatter_kws={"s": 80}); - ``` ![http://seaborn.pydata.org/_images/regression_33_0.png](img/86f9e6a8b938de1a3aeb9b237b524f0b.jpg) -If there is structure in the residuals, it suggests that simple linear regression is not appropriate: +如果残差中存在结构形状,则表明简单的线性回归不合适: -```py +```python sns.residplot(x="x", y="y", data=anscombe.query("dataset == 'II'"), scatter_kws={"s": 80}); - ``` ![http://seaborn.pydata.org/_images/regression_35_0.png](img/61c737744b3c54b93ad9bc691e4461bc.jpg) -## Conditioning on other variables +## 其他变量关系 -The plots above show many ways to explore the relationship between a pair of variables. Often, however, a more interesting question is “how does the relationship between these two variables change as a function of a third variable?” This is where the difference between [`regplot()`](../generated/seaborn.regplot.html#seaborn.regplot "seaborn.regplot") and [`lmplot()`](../generated/seaborn.lmplot.html#seaborn.lmplot "seaborn.lmplot") appears. While [`regplot()`](../generated/seaborn.regplot.html#seaborn.regplot "seaborn.regplot") always shows a single relationship, [`lmplot()`](../generated/seaborn.lmplot.html#seaborn.lmplot "seaborn.lmplot") combines [`regplot()`](../generated/seaborn.regplot.html#seaborn.regplot "seaborn.regplot") with [`FacetGrid`](../generated/seaborn.FacetGrid.html#seaborn.FacetGrid "seaborn.FacetGrid") to provide an easy interface to show a linear regression on “faceted” plots that allow you to explore interactions with up to three additional categorical variables. + 上面的图显示了探索一对变量之间关系的许多方法。然而,通常,一个更有趣的问题是"这两个变量之间的关系如何随第三个变量的变化而变化?"这就是[`regplot()`](../generated/seaborn.regplot.html#seaborn.regplot "seaborn.regplot")和[`lmplot()`](../generated/seaborn.lmplot.html#seaborn.lmplot "seaborn.lmplot")的区别所在。[`regplot()`](../generated/seaborn.regplot.html#seaborn.regplot "seaborn.regplot")总是表现单一关系, [`lmplot()`](../generated/seaborn.lmplot.html#seaborn.lmplot "seaborn.lmplot")把[`regplot()`](../generated/seaborn.regplot.html#seaborn.regplot "seaborn.regplot")和 [`FacetGrid`](../generated/seaborn.FacetGrid.html#seaborn.FacetGrid "seaborn.FacetGrid")结合,以提供一个简单的界面,显示"facet"图的线性回归,使你可以探索与最多三个其他分类变量的交互。 -The best way to separate out a relationship is to plot both levels on the same axes and to use color to distinguish them: +分离关系的最佳方法是在同一轴上绘制两个级别并使用颜色来区分它们: -```py +```python sns.lmplot(x="total_bill", y="tip", hue="smoker", data=tips); - ``` -![http://seaborn.pydata.org/_images/regression_37_0.png](img/c1be6d813a335d32887cfd051ef9167f.jpg) +![http://seaborn.pydata.org/_images/regression_37_0.png](/Users/huangcancan/Dropbox%20(Brown)/3_Private_Files/img/c1be6d813a335d32887cfd051ef9167f.jpg) -In addition to color, it’s possible to use different scatterplot markers to make plots the reproduce to black and white better. You also have full control over the colors used: +除了颜色之外,还可以使用不同的散点图标记来使绘图更好地再现为黑白。你还可以完全控制使用的颜色: -```py +```python sns.lmplot(x="total_bill", y="tip", hue="smoker", data=tips, markers=["o", "x"], palette="Set1"); - ``` -![http://seaborn.pydata.org/_images/regression_39_0.png](img/b065f9278c97b242c9a517aa98c090fa.jpg) +![http://seaborn.pydata.org/_images/regression_39_0.png](/Users/huangcancan/Dropbox%20(Brown)/3_Private_Files/img/b065f9278c97b242c9a517aa98c090fa.jpg) -To add another variable, you can draw multiple “facets” which each level of the variable appearing in the rows or columns of the grid: +要添加另一个变量,你可以绘制多个"facet",其中每个级别的变量出现在网络的行或列中: -```py +```python sns.lmplot(x="total_bill", y="tip", hue="smoker", col="time", data=tips); - ``` -![http://seaborn.pydata.org/_images/regression_41_0.png](img/02113b4a6b876c8e3b32dd2bb7eae74c.jpg) +![http://seaborn.pydata.org/_images/regression_41_0.png](/Users/huangcancan/Dropbox%20(Brown)/3_Private_Files/img/02113b4a6b876c8e3b32dd2bb7eae74c.jpg) -```py +```python sns.lmplot(x="total_bill", y="tip", hue="smoker", col="time", row="sex", data=tips); - ``` -![http://seaborn.pydata.org/_images/regression_42_0.png](img/eb0843cd39205e7144eb4acdf1b8356d.jpg) +![http://seaborn.pydata.org/_images/regression_42_0.png](/Users/huangcancan/Dropbox%20(Brown)/3_Private_Files/img/eb0843cd39205e7144eb4acdf1b8356d.jpg) -## Controlling the size and shape of the plot +## 控制绘图的大小和形状 -Before we noted that the default plots made by [`regplot()`](../generated/seaborn.regplot.html#seaborn.regplot "seaborn.regplot") and [`lmplot()`](../generated/seaborn.lmplot.html#seaborn.lmplot "seaborn.lmplot") look the same but on axes that have a different size and shape. This is because [`regplot()`](../generated/seaborn.regplot.html#seaborn.regplot "seaborn.regplot") is an “axes-level” function draws onto a specific axes. This means that you can make multi-panel figures yourself and control exactly where the regression plot goes. If no axes object is explicitly provided, it simply uses the “currently active” axes, which is why the default plot has the same size and shape as most other matplotlib functions. To control the size, you need to create a figure object yourself. +在之前,我们注意到[`regplot()`](../generated/seaborn.regplot.html#seaborn.regplot "seaborn.regplot")和[`lmplot()`](../generated/seaborn.lmplot.html#seaborn.lmplot "seaborn.lmplot")生成的默认图看起来相同,但却具有不同的大小和形状。这是因为[`regplot()`](../generated/seaborn.regplot.html#seaborn.regplot "seaborn.regplot")是一个"轴级"函数,它绘制在特定的轴上。这意味着你可以自己制作多面板图形并精确控制回归图的位置。如果没有明确提供轴对象,它只使用"当前活动"轴,这就是默认绘图与大多数其他matplotlib函数具有相同大小和形状的原因。要控制大小,你需要自己创建一个图形对象。 -```py +```python f, ax = plt.subplots(figsize=(5, 6)) sns.regplot(x="total_bill", y="tip", data=tips, ax=ax); - ``` -![http://seaborn.pydata.org/_images/regression_44_0.png](img/a94aa08c017f4688743921ccc9d8a4d0.jpg) +![http://seaborn.pydata.org/_images/regression_44_0.png](/Users/huangcancan/Dropbox%20(Brown)/3_Private_Files/img/a94aa08c017f4688743921ccc9d8a4d0.jpg) -In contrast, the size and shape of the [`lmplot()`](../generated/seaborn.lmplot.html#seaborn.lmplot "seaborn.lmplot") figure is controlled through the [`FacetGrid`](../generated/seaborn.FacetGrid.html#seaborn.FacetGrid "seaborn.FacetGrid") interface using the `size` and `aspect` parameters, which apply to each _facet_ in the plot, not to the overall figure itself: +相比之下,[`lmplot()`](../generated/seaborn.lmplot.html#seaborn.lmplot "seaborn.lmplot")图的大小和形状是通过[`lmplot()`](http://typora-app/generated/seaborn.lmplot.html#seaborn.lmplot)接口,使用`size`和`aspect`参数控制,这些参数适用于绘图中的每个`facet`,而不是整个图形本身: -```py +```python sns.lmplot(x="total_bill", y="tip", col="day", data=tips, col_wrap=2, height=3); - ``` -![http://seaborn.pydata.org/_images/regression_46_0.png](img/fce6798715088ab4d9f615ae89a67b2c.jpg) +![http://seaborn.pydata.org/_images/regression_46_0.png](/Users/huangcancan/Dropbox%20(Brown)/3_Private_Files/img/fce6798715088ab4d9f615ae89a67b2c.jpg) -```py +```python sns.lmplot(x="total_bill", y="tip", col="day", data=tips, aspect=.5); - ``` -![http://seaborn.pydata.org/_images/regression_47_0.png](img/ea6e78ca63d3d86dece589f475f2338d.jpg) +![http://seaborn.pydata.org/_images/regression_47_0.png](/Users/huangcancan/Dropbox%20(Brown)/3_Private_Files/img/ea6e78ca63d3d86dece589f475f2338d.jpg) -## Plotting a regression in other contexts +## 在其他情境中绘制回归 -A few other seaborn functions use [`regplot()`](../generated/seaborn.regplot.html#seaborn.regplot "seaborn.regplot") in the context of a larger, more complex plot. The first is the [`jointplot()`](../generated/seaborn.jointplot.html#seaborn.jointplot "seaborn.jointplot") function that we introduced in the [distributions tutorial](distributions.html#distribution-tutorial). In addition to the plot styles previously discussed, [`jointplot()`](../generated/seaborn.jointplot.html#seaborn.jointplot "seaborn.jointplot") can use [`regplot()`](../generated/seaborn.regplot.html#seaborn.regplot "seaborn.regplot") to show the linear regression fit on the joint axes by passing `kind="reg"`: +其他一些seaborn函数在更大,更复杂的图中使用[`regplot()`](../generated/seaborn.regplot.html#seaborn.regplot "seaborn.regplot")。第一个是我们在[发行教程](distributions.html#distribution-tutorial)中引入的[`jointplot()`](../generated/seaborn.jointplot.html#seaborn.jointplot "seaborn.jointplot")。除了前面讨论的绘制风格,[`jointplot()`](../generated/seaborn.jointplot.html#seaborn.jointplot "seaborn.jointplot") 可以使用[`regplot()`](../generated/seaborn.regplot.html#seaborn.regplot "seaborn.regplot")通过传递`kind="reg"`来显示轴上的线性回归拟合: -```py +```python sns.jointplot(x="total_bill", y="tip", data=tips, kind="reg"); - ``` -![http://seaborn.pydata.org/_images/regression_49_0.png](img/0a3f41c0a016c66f0f3379c128f550b9.jpg) +![http://seaborn.pydata.org/_images/regression_49_0.png](/Users/huangcancan/Dropbox%20(Brown)/3_Private_Files/img/0a3f41c0a016c66f0f3379c128f550b9.jpg) -Using the [`pairplot()`](../generated/seaborn.pairplot.html#seaborn.pairplot "seaborn.pairplot") function with `kind="reg"` combines [`regplot()`](../generated/seaborn.regplot.html#seaborn.regplot "seaborn.regplot") and [`PairGrid`](../generated/seaborn.PairGrid.html#seaborn.PairGrid "seaborn.PairGrid") to show the linear relationship between variables in a dataset. Take care to note how this is different from [`lmplot()`](../generated/seaborn.lmplot.html#seaborn.lmplot "seaborn.lmplot"). In the figure below, the two axes don’t show the same relationship conditioned on two levels of a third variable; rather, [`PairGrid()`](../generated/seaborn.PairGrid.html#seaborn.PairGrid "seaborn.PairGrid") is used to show multiple relationships between different pairings of the variables in a dataset: +使用[`pairplot()`](../generated/seaborn.pairplot.html#seaborn.pairplot "seaborn.pairplot")函数与`kind="reg"`将 [`regplot()`](../generated/seaborn.regplot.html#seaborn.regplot "seaborn.regplot")和[`PairGrid`](../generated/seaborn.PairGrid.html#seaborn.PairGrid "seaborn.PairGrid") 结合起来,来显示数据集中变量的线性关系。请注意这与[`lmplot()`](../generated/seaborn.lmplot.html#seaborn.lmplot "seaborn.lmplot")的不同之处。在下图中,两个轴在第三变量上的两个级别上没有显示相同的关系;相反,[`PairGrid()`](../generated/seaborn.PairGrid.html#seaborn.PairGrid "seaborn.PairGrid")用于显示数据集中变量的不同配对之间的多个关系。 -```py +```python sns.pairplot(tips, x_vars=["total_bill", "size"], y_vars=["tip"], height=5, aspect=.8, kind="reg"); - ``` -![http://seaborn.pydata.org/_images/regression_51_0.png](img/65fcd97ee44e136d797a4d343a58cc4f.jpg) +![http://seaborn.pydata.org/_images/regression_51_0.png](/Users/huangcancan/Dropbox%20(Brown)/3_Private_Files/img/65fcd97ee44e136d797a4d343a58cc4f.jpg) -Like [`lmplot()`](../generated/seaborn.lmplot.html#seaborn.lmplot "seaborn.lmplot"), but unlike [`jointplot()`](../generated/seaborn.jointplot.html#seaborn.jointplot "seaborn.jointplot"), conditioning on an additional categorical variable is built into [`pairplot()`](../generated/seaborn.pairplot.html#seaborn.pairplot "seaborn.pairplot") using the `hue` parameter: +像[`lmplot()`](../generated/seaborn.lmplot.html#seaborn.lmplot "seaborn.lmplot"),但不像[`jointplot()`](../generated/seaborn.jointplot.html#seaborn.jointplot "seaborn.jointplot"),额外的分类变量调节是通过`hue`参数内置在函数[`pairplot()`](../generated/seaborn.pairplot.html#seaborn.pairplot "seaborn.pairplot")中: -```py +```python sns.pairplot(tips, x_vars=["total_bill", "size"], y_vars=["tip"], hue="smoker", height=5, aspect=.8, kind="reg"); - ``` -![http://seaborn.pydata.org/_images/regression_53_0.png](img/b166f746ed213b5ac4e495320f99b0fd.jpg) \ No newline at end of file +![http://seaborn.pydata.org/_images/regression_53_0.png]() \ No newline at end of file -- GitLab