I am trying to write a function to loop through the selected columns and plot subplots of countplot but it just plots only one of the plots and also gives a error message of "AxesSubplot" object does not support indexing. But the codes work for histograms.
Appreciate the help in advance.
def subplot_countplot(dataframe, list_of_columns, list_of_titles, list_of_xlabels):
fig, ax = plt.subplots(ncols=2, figsize=(16,8))
for i, column in enumerate(list_of_columns):
ax = sns.countplot(x=dataframe[column], data=marital)
ax[i].set_title(list_of_titles[i], fontsize=12)
ax[i].set_xlabel(list_of_xlabels[i], fontsize=12)
ax[i].set_ylabel('Number of Marriages', fontsize=12)
plt.show()
*#Barcharts for trends in marriages*
list_of_columns = ['yearoflatestmarriage','monthoflatestmarriage']
list_of_titles = ['Year of Marriage','Month of Marriage']
list_of_xlabels=['Count of Marriage' for i in list_of_columns]
subplot_countplot(marital, list_of_columns, list_of_titles, list_of_xlabels)
list_of_columns = ['yearoflatestmarriage','monthoflatestmarriage']
list_of_titles = ['Year of Marriage','Month of Marriage']
list_of_xlabels=['Count of Marriage' for i in list_of_columns]
subplot_countplot(marital, list_of_columns, list_of_titles, list_of_xlabels)