I am trying to create subplots inside for loop for various columns of the dataset. I am using the California housing dataset from sklearn. So, there are 4 columns and I want to display three figures for each column in a subplot. I have provided the code which I have tried. Can somebody help me with this issue? Can we make it dynamic so that if I need to add more figure then we can add easily with title?
from sklearn.datasets import fetch_california_housing
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
california_housing = fetch_california_housing(as_frame=True)
# california_housing.frame.head()
features_of_interest = ["AveRooms", "AveBedrms", "AveOccup", "Population"]
california_housing.frame[features_of_interest]
fig, axes = plt.subplots(4, 3)
for cols in features_of_interest:
# scatterplot
sns.scatterplot(x=california_housing.frame[cols], y=california_housing.target)
# histogram
sns.histplot(x=california_housing.frame[cols], y=california_housing.target)
#qqplot
sm.qqplot(california_housing.frame[cols], line='45')
plt.show()