\

Photo from network article/Yi Zhu \

Seaborn is a Python visualization library based on Matplotlib. It provides an advanced interface to draw attractive statistical graphs. Seaborn is actually a more advanced API package based on Matplotlib, which makes it much easier to draw and refine your drawings without a lot of tweaking. \

Today we’re going to talk about Pairplot, so without further ado, let’s get straight to the point. \

Note: All code is implemented in IPython Notebook

· Is · wen · come

pairplot

**** Pairplot “pair” means a pair. Pairplot mainly shows the relationship between two variables (linear or nonlinear, with or without obvious correlation). As usual, take a general overview of the API of Pairplot.

The following uses iris data set to introduce the usage of pairplot. The Iris data set has been used a lot, but most people (and I, too) probably don’t know what an iris looks like. Here’s a picture of an iris.

Import related packages and configure related parameters

import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
sns.set_style('white', {'font.sans-serif': ['simhei'.'Arial']})
Copy the code
Data =sns.load_dataset("iris"Rename (columns={data.rename(columns={"sepal_length":"Sepal length"."sepal_width":"Sepals wide"."petal_length":"Long petals"."petal_width":"Petal width"."species":"Kind"},inplace=True)
kind_dict = {
    "setosa":"Iris mountain"."versicolor":"Iris variegated"."virginica":"Irises Virginia"
}
data["Kind"] = data["Kind"].map(kind_dict) data.head() # The contents of the dataset are as followsCopy the code

Let’s get an intuition of what pairplot looks like

sns.pairplot(data)
Copy the code

It can be seen that the diagonal line is the histogram (distribution map) of each attribute, while the non-diagonal line is the correlation map between two different attributes. From the figure, we can find that there is an obvious correlation between the length and width of petals, and between the length and width of sepals and the length and width of petals.

Here are the main parameters of pairplot and their usage

Kind: Controls the type of non-diagonal images. “Scatter” and “reg”““` are optional

Diag_kind: Controls the type of diagonals. “hist” and “kDE” are optional

sns.pairplot(data,kind="reg",diag_kind="kde")
Copy the code

Setting the KIND parameter to “reg” will fit a regression line for the non-diagonal scatter plot, showing the relationship between variables more intuitively.

What are the distinctive features of the sepals and petals of different kinds of flowers? We use the Hue parameter to separate different flower species for further analysis.

Hue: Classifies a field

SNS. Pairplot (data, Hue ="Kind"Copy the code

We can found from after hue classification of pairplot, whether from the map on the diagonal or from the sorted scatter plot, all can see that for different kinds of flowers, the length of the sepals and petals, petals wide distribution differences, in other words, these properties can be help us to identify different kinds of flowers.

For example, for flowers with short sepals and petals and narrow petal width, it is most likely to be iris cerasus.

Of course, you can use the palette parameter to bring up the color you want

Palette

sns.pairplot(data,hue="Kind",palette="husl")
Copy the code

Markers: Controls the style of the scatter

sns.pairplot(data,hue="Kind",markers=["+"."s"."D"])
Copy the code

When we want to investigate the relationship between two (or more) variables separately, we simply specify the variables you want to investigate using the VARS parameter

Vars, X_vars,y_vars: Select a specific field in the data and pass it in as a list

# Select with the VARS parameter alone"Sepal length"and"Long petals"Sns.pairplot (data,vars=["Sepal length"."Long petals"]) 
Copy the code

Pairplot (data,x_vars=[);"Sepal length"."Petal width"],
             y_vars=["Sepals wide"."Long petals"]) 
Copy the code

More styles can be controlled through plot_kws and DIAG_kws

Plot_kws: Used to control the style of graphs that are not on diagonal lines

Diag_kws: Used to control the style of the diagonals above

sns.pairplot(data,diag_kind="kde",
             plot_kws=dict(s=50,edgecolor="w",color="g",alpha=. 5),
             diag_kws=dict(shade=True,color="r")) 
Copy the code

Click become:Community registered members ** like the article, click the **Looking at the