logo
Loading...

畫圖出現計次錯誤問題 - Cupoy

再最後畫圖時 出現錯誤如下, 雖然圖有出來 但想請問是哪邊有問題# 使用不同的 HOUSETYPE_...

ml100-3,ml100-3-d19

畫圖出現計次錯誤問題

2019/09/29 09:27 下午
機器學習共學討論版
陳明宣
觀看數:30
回答數:2
收藏數:0
ml100-3
ml100-3-d19

再最後畫圖時 出現錯誤如下, 雖然圖有出來 但想請問是哪邊有問題


# 使用不同的 HOUSETYPE_MODE 類別繪製圖形, 並使用 subplot 排版

test = app_train[['SK_ID_CURR','TARGET','AMT_INCOME_TOTAL']]

test['AMT_INCOME_TOTAL_group']=pd.qcut(app_train['AMT_INCOME_TOTAL'],11)

unique_house_type = list(test['AMT_INCOME_TOTAL_group'])

rows = len(unique_house_type)

cols = nrows // 2

unique_house_type[1]

plt.figure(figsize=(10,30))

for i in range(len(unique_house_type)):

   plt.subplot(nrows, ncols, i+1)

   sns.distplot(app_train.loc[(test['AMT_INCOME_TOTAL_group'] == unique_house_type[i]) & app_train['TARGET']==1,'AMT_INCOME_TOTAL'])


   plt.title(str(unique_house_type[i]))

plt.legend()

plt.show()    

--------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-72-b6b13268dc1f> in <module>
     1 plt.figure(figsize=(10,30))
     2 for i in range(len(unique_house_type)):
----> 3     plt.subplot(nrows, ncols, i+1)
     4     sns.distplot(app_train.loc[(test['AMT_INCOME_TOTAL_group'] == unique_house_type[i]) & app_train['TARGET']==1,'AMT_INCOME_TOTAL'])
     5

~/anaconda3/lib/python3.7/site-packages/matplotlib/pyplot.py in subplot(*args, **kwargs)
  1068
  1069     fig = gcf()
-> 1070     a = fig.add_subplot(*args, **kwargs)
  1071     bbox = a.bbox
  1072     byebye = []

~/anaconda3/lib/python3.7/site-packages/matplotlib/figure.py in add_subplot(self, *args, **kwargs)
  1412                     self._axstack.remove(ax)
  1413
-> 1414             a = subplot_class_factory(projection_class)(self, *args, **kwargs)
  1415
  1416         return self._add_axes_internal(key, a)

~/anaconda3/lib/python3.7/site-packages/matplotlib/axes/_subplots.py in __init__(self, fig, *args, **kwargs)
    57                 if num < 1 or num > rows*cols:
    58                     raise ValueError(
---> 59                         f"num must be 1 <= num <= {rows*cols}, not {num}")
    60                 self._subplotspec = GridSpec(
    61                         rows, cols, figure=self.figure)[int(num) - 1]

ValueError: num must be 1 <= num <= 10, not 11