# seaborn.PairGrid

```py
class seaborn.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)
```

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 [tutorial](../tutorial/axis_grids.html#grid-tutorial) for more information.

```py
__init__(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)
```

Initialize the plot figure and PairGrid object.

参数：`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 -&gt; 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

Easily drawing common uses of [`PairGrid`](#seaborn.PairGrid "seaborn.PairGrid").Subplot grid for plotting conditional relationships.

Examples

Draw a scatterplot for each pairwise relationship:

```py
>>> import matplotlib.pyplot as plt
>>> import seaborn as sns; sns.set()
>>> iris = sns.load_dataset("iris")
>>> g = sns.PairGrid(iris)
>>> g = g.map(plt.scatter)

```

![http://seaborn.pydata.org/_images/seaborn-PairGrid-1.png](img/34fc6de3cfc117757cc0e5f658a06928.jpg)

Show a univariate distribution on the diagonal:

```py
>>> g = sns.PairGrid(iris)
>>> g = g.map_diag(plt.hist)
>>> g = g.map_offdiag(plt.scatter)

```

![http://seaborn.pydata.org/_images/seaborn-PairGrid-2.png](img/7e2b84efc57efecba1f8c1bfad570874.jpg)

(It’s not actually necessary to catch the return value every time, as it is the same object, but it makes it easier to deal with the doctests).

Color the points using a categorical variable:

```py
>>> g = sns.PairGrid(iris, hue="species")
>>> g = g.map_diag(plt.hist)
>>> g = g.map_offdiag(plt.scatter)
>>> g = g.add_legend()

```

![http://seaborn.pydata.org/_images/seaborn-PairGrid-3.png](img/6df84055fcde05fec3e0b9794967ad71.jpg)

Use a different style to show multiple histograms:

```py
>>> g = sns.PairGrid(iris, hue="species")
>>> g = g.map_diag(plt.hist, histtype="step", linewidth=3)
>>> g = g.map_offdiag(plt.scatter)
>>> g = g.add_legend()

```

![http://seaborn.pydata.org/_images/seaborn-PairGrid-4.png](img/b269cdc188b02e86196c919d1bd87402.jpg)

Plot a subset of variables

```py
>>> g = sns.PairGrid(iris, vars=["sepal_length", "sepal_width"])
>>> g = g.map(plt.scatter)

```

![http://seaborn.pydata.org/_images/seaborn-PairGrid-5.png](img/81ab9afd2faa6448de3c2b5a73ea3320.jpg)

Pass additional keyword arguments to the functions

```py
>>> g = sns.PairGrid(iris)
>>> g = g.map_diag(plt.hist, edgecolor="w")
>>> g = g.map_offdiag(plt.scatter, edgecolor="w", s=40)

```

![http://seaborn.pydata.org/_images/seaborn-PairGrid-6.png](img/ff58dc3588f11a9e3f9291926a0c86ff.jpg)

Use different variables for the rows and columns:

```py
>>> g = sns.PairGrid(iris,
...                  x_vars=["sepal_length", "sepal_width"],
...                  y_vars=["petal_length", "petal_width"])
>>> g = g.map(plt.scatter)

```

![http://seaborn.pydata.org/_images/seaborn-PairGrid-7.png](img/0d8364e9bb731fa5d89b998087ba0635.jpg)

Use different functions on the upper and lower triangles:

```py
>>> g = sns.PairGrid(iris)
>>> g = g.map_upper(plt.scatter)
>>> g = g.map_lower(sns.kdeplot, cmap="Blues_d")
>>> g = g.map_diag(sns.kdeplot, lw=3, legend=False)

```

![http://seaborn.pydata.org/_images/seaborn-PairGrid-8.png](img/58e8af844e6f097dc5995d7a2be70b0e.jpg)

Use different colors and markers for each categorical level:

```py
>>> g = sns.PairGrid(iris, hue="species", palette="Set2",
...                  hue_kws={"marker": ["o", "s", "D"]})
>>> g = g.map(plt.scatter, linewidths=1, edgecolor="w", s=40)
>>> g = g.add_legend()

```

![http://seaborn.pydata.org/_images/seaborn-PairGrid-9.png](img/c9a2068151affcefc99a7b280ab0a52b.jpg)

Methods

| [`__init__`](#seaborn.PairGrid.__init__ "seaborn.PairGrid.__init__")(data[, hue, hue_order, palette, …]) | Initialize the plot figure and PairGrid object. |
| `add_legend`([legend_data, title, label_order]) | Draw a legend, maybe placing it outside axes and resizing the figure. |
| [`map`](seaborn.PairGrid.map.html#seaborn.PairGrid.map "seaborn.PairGrid.map")(func, **kwargs) | Plot with the same function in every subplot. |
| [`map_diag`](seaborn.PairGrid.map_diag.html#seaborn.PairGrid.map_diag "seaborn.PairGrid.map_diag")(func, **kwargs) | Plot with a univariate function on each diagonal subplot. |
| [`map_lower`](seaborn.PairGrid.map_lower.html#seaborn.PairGrid.map_lower "seaborn.PairGrid.map_lower")(func, **kwargs) | Plot with a bivariate function on the lower diagonal subplots. |
| [`map_offdiag`](seaborn.PairGrid.map_offdiag.html#seaborn.PairGrid.map_offdiag "seaborn.PairGrid.map_offdiag")(func, **kwargs) | Plot with a bivariate function on the off-diagonal subplots. |
| [`map_upper`](seaborn.PairGrid.map_upper.html#seaborn.PairGrid.map_upper "seaborn.PairGrid.map_upper")(func, **kwargs) | Plot with a bivariate function on the upper diagonal subplots. |
| `savefig`(*args, **kwargs) | Save the figure. |
| `set`(**kwargs) | Set attributes on each subplot Axes. |