I have written the following code to plot 6 pie charts in different subplots, but I get an error. This code works correctly if I use it to plot only 2 charts, but produces an an error for anything more than that.
I have 6 categorical variables in my dataset, the names of which are stored in the list cat_cols
. The charts are to be plotted from the training data train
.
CODE
fig, axes = plt.subplots(2, 3, figsize=(24, 10))
for i, c in enumerate(cat_cols):
train[c].value_counts()[::-1].plot(kind = 'pie', ax=axes[i], title=c, autopct='%.0f', fontsize=18)
axes[i].set_ylabel('')
plt.tight_layout()
ERROR
AttributeError: 'numpy.ndarray' object has no attribute 'get_figure'
How do we rectify this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…