Home > Software design >  How to solve 'numpy.ndarray' object has no attribute 'get_figure' error when sub
How to solve 'numpy.ndarray' object has no attribute 'get_figure' error when sub

Time:02-19

I want to plot my all dataframess 'oran' column with using subplot.

data contains 'oran' column.

Here is my code;

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()

But this code gives me the error 'numpy.ndarray' object has no attribute 'get_figure'

I couldn't find the way to solve this problem. How can i avoid this error?

The first 5 row of the dataset

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

CodePudding user response:

The problem is that axes is a 2-dimensional array (shape (6,2)).

The loop for ax in axes: ... selects 1d arrays (shape (2,)) out of it. Passing this array as ax-kwarg to temp.oran.plot(ax=ax) results in the respective error.

Using for ax in axes.flat: ... should work.

  • Related