As an example in this code I am plotting in many subplots:
fig, axs = plt.subplots(ncols=cols, nrows=rows, figsize=(16,20), sharex=False)
# Adding some distance between plots
plt.subplots_adjust(hspace = 0.3)
# Plots counter
i=0
for r in np.arange(0, rows, 1):
for c in np.arange(0, cols, 1):
if i >= len(columns): # If there is no more data columns to make plots from
axs[r, c].set_visible(False) # Hiding axes so there will be clean background
else:
# Train data histogram
hist1 = axs[r, c].hist(train[columns[i]].values,
range=(df[columns[i]].min(),
df[columns[i]].max()),
bins=40,
color="deepskyblue",
edgecolor="black",
alpha=0.7,
label="Train Dataset")
# Test data histogram
hist2 = axs[r, c].hist(test[columns[i]].values,
range=(df[columns[i]].min(),
df[columns[i]].max()),
bins=40,
color="palevioletred",
edgecolor="black",
alpha=0.7,
label="Test Dataset")
axs[r, c].set_title(columns[i], fontsize=14, pad=5)
axs[r, c].tick_params(axis="y", labelsize=13)
axs[r, c].tick_params(axis="x", labelsize=13)
axs[r, c].grid(axis="y")
axs[r, c].legend(fontsize=13)
i+=1
plt.show();
You get the axes using axs[r, c] and plot it inside that.