Why seaborn’s pairplot does not plot the first plot?

  python, python-3.x, seaborn

I am trying to make a pairplot using sns, but for some reason, it refuses to plot the first one. What may cause this issue?

Here is the fully working code:

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

df = pd.read_csv("http://web.stanford.edu/~oleg2/hse/auto/Auto.csv").dropna()
med = df.mpg.median()
df['mpg01'] = [1 if i > med else 0 for i in df.mpg]
sub = df.drop(columns=['name'])
sns.pairplot(data=sub, x_vars=sub.columns, y_vars=['mpg01'])
plt.show()

Here is the output:
enter image description here

Source: Python Questions

One Reply to “Why seaborn’s pairplot does not plot the first plot?”

  • Try moving mpg01 to be the first column, it will then plot:

    df = pd.read_csv(“http://web.stanford.edu/~oleg2/hse/auto/Auto.csv”).dropna()
    med = df.mpg.median()
    df[‘mpg01′] = [1 if i > med else 0 for i in df.mpg]
    df.insert(0,’mpg01’,df.pop(‘mpg01’))
    sub = df.drop(columns=[‘name’])
    sns.pairplot(data=sub, x_vars=sub.columns, y_vars=[‘mpg01’])
    plt.show()

LEAVE A COMMENT