0
我可以在一個1XN矩陣中容易地將我的熊貓數據框列值繪製爲子圖解。matplotlib和大熊貓在一個新的行上繪製子圖解
但是,當我想將其繪製在MXN矩陣上時,出現錯誤。
實施例:
df_play = pd.DataFrame({'a':['cat','dog','cat'],
'b':['apple','orange','orange'],
'c':['boy','boy','girl'],
'd':['chair','table','desk']
},dtype='category')
fig, axs = plt.subplots(1,len(df_play.columns),figsize=(14,6))
for i,x in enumerate(df_play.columns):
df_play[x].value_counts().plot(kind='bar',ax=axs[i])
這樣做使我的錯誤(例如,我想查看我的副區,爲2×2矩陣):
fig, axs = plt.subplots(2,len(df_play.columns)/2,figsize=(14,6))
for i,x in enumerate(df_play.columns):
df_play[x].value_counts().plot(kind='bar',ax=axs[i])
AttributeError: 'numpy.ndarray' object has no attribute 'get_figure'
感謝您的解釋!這工作 – jxn