Pair plot in Seaborn

A pair plot is a special type of FacetGrid. Pairwise relationships between all variables in the input DataFrame will be visualized as scatter plots. In addition, a series of histograms will be displayed along the diagonal axes to show the distribution of the variable in that column:

# Show a pairplot of three selected variables (vars=["Open", "Volume", "Close"])
g = sns.pairplot(stock_df, hue="Company",
vars=["Open", "Volume", "Close"])

plt.show()

We can tweak many aspects of the plot. In the next example, we will increase the aspect ratio, change the plot type in the diagonal line to KDE plot, and adjust the aesthetics of the plots using keyword arguments:

# Adjust the aesthetics of the plot
g = sns.pairplot(stock_df, hue="Company",
aspect=1.5, diag_kind="kde",
diag_kws=dict(shade=True),
plot_kws=dict(s=15, marker="+"),
vars=["Open", "Volume", "Close"])

plt.show()

Similar to other plots based on FacetGrid, we can define the variables to be displayed in each panel. We can also manually define the comparisons that matter to us instead of an all-versus-all comparison by setting the x_vars and y_vars parameters. You may also use seaborn.PairGrid() directly if you require even higher flexibility for defining comparison groups:

# Manually defining the comparisons that we are interested.
g = sns.pairplot(stock_df, hue="Company", aspect=1.5,
x_vars=["Open", "Volume"],
y_vars=["Close", "Close_change"])

plt.show()
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset