'AxesSubplot' object has no attribute 'bar_label'

Hello everyone,

I have tried to change the number size (fontsize) shown on bar plots by using bar_label. But I always get the error ‘AxesSubplot’ object has no attribute ‘bar_label’. I have updated my package matplotlib but it doesn’t solve my problem. If anyone knows how to solve it or any idea please let me know.
Here is my code:

labels = ['Day1', 'Day2', 'Day3', 'Day4', 'Day5', 'Day6', 'Day7']
x = np.arange(len(labels))
width = 0.35  # the width of the bars
fig5, ax = plt.subplots()
rects1 = ax.bar(x - width / 2, round(self.EMS.df_aut['Autarchy'], 2), width, label='Autarchy')
rects2 = ax.bar(x + width / 2, round(self.EMS.df_aut['Self_consumption'], 2), width,
                        label='Self_consumption')                           
ax.set_ylabel('Percentage')
ax.set_title('Autarchy and Self_consumption Rate of {} with EMS run{}'.format(self.name, run_type))
ax.set_xticks(x)
ax.set_xticklabels(labels)
ax.bar_label(rects1,fontsize=6)
ax.bar_label(rects2, fontsize=6)

Thanks

bar_label is relatively new. If you don’t have the method on your axes, you are using an old version.

1 Like

My matplotlib version is 3.3.4 and I thought it was the newest. Do you know what the latest version is?

You can see the version at the top of the documentation. bar_label came in for 3.4.

3 Likes

Thank you so much for letting me know :slight_smile:

Thank you so much !!!