0
$\begingroup$

I want to create scatterplot of target variable with all the other variables in dataframe. Just like we create pairplot but as pairplot with large number of variables will take lot of time and computing memory, it is required to draw scatter plot containing all the variables with target variable. So tried implementing it in for loop, but only last one got rendered properly.

count=1
for i in df.columns:
    plt.subplot(n,1,count)
    plt.figure(figsize=[5,5])
    sns.scatterplot(df["cnt"],df[i])
    count+=1

output: only last plot is rendered properly

enter image description here

$\endgroup$
0
$\begingroup$

Just get rid of the plt.figure(figsize=[5,5])

count=1
for i in df.columns:
    plt.subplot(n,1,count)
    sns.scatterplot(df["cnt"],df[i])
    count+=1

plt.show()

or use this to make it more beautier (Adjust the first two parameters of subplot function, i.e. 3, 2, to if you have more columns. First parameter specifies the number of rows for subplots in the plot, and second parameter specifies number of columns)

count=1
plt.subplots(figsize=(10, 8))
for i in df.columns:
    plt.subplot(3,2,count)
    sns.scatterplot(df["cnt"],df[i])
    count+=1

plt.show()
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.