0

I was trying to plot 2 scatter plots, using this code:

plt.figure(figsize=(12,8))
scatter_plots = ['Age','Annual Income (k$)']

for col in scatter_plots:
    i=1
    plt.subplot(1, 2, i)
    sns.scatterplot(color='r', x=df['Spending Score (1-100)'], y=df[col])
    plt.show()
    i+=1

However, as a result, got this,enter image description here and fig size was applied only to the first plot, and both plots were not horizontally but vertically aligned. Here is the screenshoot

JohanC
  • 59,187
  • 8
  • 19
  • 45
Zexxxx
  • 59
  • 6
  • 2
    Please read [how to create subplots](https://matplotlib.org/stable/gallery/subplots_axes_and_figures/subplots_demo.html). Seaborn takes then the axes as a parameter like `sns.scatterplot(..., ax=ax[1])`. `plt.show()` should be outside the loop. However, given that you probably have a pandas dataframe, you should be able to avoid looping and just provide [seaborn with the data and the desired scatter plot outline](https://seaborn.pydata.org/tutorial/relational.html#relating-variables-with-scatter-plots). – Mr. T Jan 11 '22 at 15:42

0 Answers0