Skip to content
Advertisement

Bar chart plotting issue: TypeError: ‘AxesSubplot’ object is not iterable

Below shown is the categorical data detail for the bar chart, which is from a specific DataFrame column i.e. coast

JavaScript

Shown below syntax is the defined function used, to get the bar chart.

JavaScript

However, the bar chart does appears without the values on the bar which is shown below.

JavaScript

enter image description here

But the below error message appears

JavaScript

How could I resolve the above error to get the below bar chart.

enter image description here

Advertisement

Answer

As @Henry Ecker commented, you should be iterating over ax.patches. The pandas plot function is returning the axis not the patches/rectangles.

enter image description here

JavaScript

Alternatively, just make the plot and get your own value counts. The X axis for bar charts is just an array 0 to number of bars (2 in this case).

enter image description here

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement