該函數返回的是子畫布的對象。
代碼:
fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, figsize=(15, 8))//fig是整體畫布,ax1到ax4是子畫布對象。
train_loan_fr.groupby('grade')['grade'].count().plot(kind='barh', ax=ax1, title='Count of grade fraud')
train_loan_nofr.groupby('grade')['grade'].count().plot(kind='barh', ax=ax2, title='Count of grade non-fraud')
train_loan_fr.groupby('employmentLength')['employmentLength'].count().plot(kind='barh', ax=ax3, title='Count of employmentLength fraud')
train_loan_nofr.groupby('employmentLength')['employmentLength'].count().plot(kind='barh', ax=ax4, title='Count of employmentLength non-fraud')
在plot函數中ax參數傳入ax1,ax2。分別畫在不同的畫布上。
否則就需要plt.subplot(221)后掉用一個plot繪圖函數。
繪制完成后繼續用plt.subplot(222)后繼續調用繪圖函數。