![](/img/trans.png)
[英]How to fix 'numpy.ndarray' object has no attribute 'get_figure' when plotting subplots
[英]How to solve 'numpy.ndarray' object has no attribute 'get_figure' error when subplotting?
我想 plot 我的所有數據框 'oran' 列使用子圖。
數據包含“oran”列。
這是我的代碼;
fig, axes = plt.subplots(6,2, figsize=(20,20))
for ax in axes:
for month in dftm.month_base_valor.unique():
temp = dftm[dftm.month_base_valor.eq(month)]
#display(temp)
temp.oran.plot(ax=ax)
fig.tight_layout()
但是這段代碼給我錯誤 'numpy.ndarray' object has no attribute 'get_figure'
我找不到解決這個問題的方法。 我怎樣才能避免這個錯誤?
數據集的前 5 行
month_base_valor aylık_total valor_tarihi gunluk_total oran year
0 2017-01 11111.50 20170102 11111.37 0.00 2017
1 2017-01 11111.50 20170103 11111.66 0.00 2017
2 2017-01 11111.50 20170104 11111.97 0.00 2017
3 2017-01 11111.50 20170105 11111.09 0.01 2017
4 2017-01 11111.50 20170106 11111.74 0.01 2017
問題是axes
是一個二維數組(形狀(6,2)
)。
for ax in axes: ...
的循環從中選擇 1d arrays (shape (2,)
)。 將此數組作為ax
-kwarg 傳遞給temp.oran.plot(ax=ax)
會導致相應的錯誤。
使用for ax in axes.flat: ...
應該可以。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.