0

I have data with 9 features, I was trying to plot a scatter plot between the variable to identify their relation for EDA.

I used the following code

fig, ax = plt.subplots(figsize=(8,6))

ax.scatter(Data['BMI'], Data['SkinThickness'],color = 'green') # Very closely correlated
ax.scatter(Data['BMI'], Data['Glucose'],color = 'blue')
ax.scatter(Data['BMI'], Data['Pregnancies'],color = 'red')
ax.scatter(Data['BMI'], Data['Age'],color = 'purple')
ax.scatter(Data['BMI'], Data['BloodPressure'],color = 'yellow')
ax.scatter(Data['BMI'], Data['Insulin'],color = 'black') # Highly scattered

plt.show()

Can anyone guide me as to how I can split these into different subplots one next to another, help would be really appreciated.

Sid
  • 163
  • 7

1 Answers1

1

Do this:

fig, ax = plt.subplots(2, 3, figsize = (8, 6)) # 2,3 means there will be in total 6 subplots lying in `2 x 3` matrix.

Then you can access them like:

ax[0,0].scatter(Data['BMI'], Data['SkinThickness'],color = 'green') # Very closely correlated
ax[0,1].scatter(Data['BMI'], Data['Glucose'],color = 'blue')

ax is actually numpy array of arrays containing axes objects:

>>> print(ax)
[[<matplotlib.axes._subplots.AxesSubplot object at 0x7fc5260dd4a8>
  <matplotlib.axes._subplots.AxesSubplot object at 0x7fc5201b22e8>
  <matplotlib.axes._subplots.AxesSubplot object at 0x7fc520189048>]
 [<matplotlib.axes._subplots.AxesSubplot object at 0x7fc52011fac8>
  <matplotlib.axes._subplots.AxesSubplot object at 0x7fc5200d8b00>
  <matplotlib.axes._subplots.AxesSubplot object at 0x7fc52008db38>]]
Vicrobot
  • 3,795
  • 1
  • 17
  • 31