【发布时间】:2019-04-07 07:02:33
【问题描述】:
我想为数据框中的列列表创建子图。但是,当我运行下面的代码时,我得到了与轴相关的索引错误
TypeError: 'AxesSubplot' 对象不支持索引
%matplotlib inline
import seaborn as sns
import matplotlib.pyplot as plt
nr_rows = 1
nr_cols = 3
cols_review = ['home_ownership', 'verification_status', 'loan_status']
li_col_reviews = list(cols_review)
fig, axs = plt.subplots(nr_rows, nr_cols, figsize=(nr_cols*4,nr_rows*3))
for r in range(0,nr_rows):
for c in range(0, nr_cols):
col = r*nr_cols+c
if col < len(li_col_reviews):
col_count = pdf[li_col_reviews[col]].value_counts()
sns.set(style="darkgrid")
sns.barplot(col_count.index, col_count.values, alpha=0.9,ax = axs[r][c])
plt.ylabel('Number of Occurrences', fontsize=12)
plt.xlabel(col, fontsize=12)
plt.tight_layout()
plt.show()
【问题讨论】:
标签: python pandas seaborn subplot