Home > front end >  How to change the "shape" of pairplot in Seaborn?
How to change the "shape" of pairplot in Seaborn?

Time:12-04

I plotted this pairplot correlating only one features with all the others, how can i visualize it in a better way? I need to visualize 4 columns. In the official documentation of pairplot i can't find the option.

This is the df: This is the df

This is the part of the code:

sns.pairplot(data=dftrain,
              y_vars=['medv'],
              x_vars=dftrain.columns[:-1])

This is the plot: This is the plot

CodePudding user response:

The shape of a pairplot can't be changed. But, you can create a similar relplot if you convert the dataframe to long form.

Here is some simple example code, starting from dummy data:

import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
import numpy as np

df = pd.DataFrame(np.random.rand(300, 14), columns=[*"abcdefghijklmn"])
df_long = df.melt(id_vars=df.columns[-1], value_vars=df.columns[:-1])

g = sns.relplot(df_long, x=df.columns[-1], y='value', col='variable', col_wrap=4, height=2)

sns.relplot

CodePudding user response:

You can use enter image description here

  • Related