AxesSubplot' object has no attribute 'datavalues'

Hello everyone:
I want to generate a bar plot based on my data by using ‘bar_label’, But I always get the error ‘AxesSubplot’ object has no attribute ‘datavalues’. I’m using the version of matplotlib “3.5.3”. If anyone knows how to solve my problem, please tell me how to do. Thank you very much!
Here is my code:

import pandas as pd
import matplotlib.pyplot as plt
import matplotlib
from matplotlib.ticker import FuncFormatter


filename = 'cagr_data.xlsx'
df = pd.read_excel(filename, index_col=0, sheet_name='Sheet2')

fig, ax = plt.subplots(figsize=(10,5), dpi=100)
rects =, legend=True, fontsize=15)

def percentage(x, pos):
    return '{:.0%}'.format(x)

ax.set_xticklabels(ax.get_xticklabels(), rotation=0, ha='center')
ax.bar_label(rects, label_type='edge')

Thanks again.

bar_label is supposed to be used on the container returned from Matplotlib’s bar.

You are using Panda’s bar, which returns a (list of) Axes, not the container.

Understood. Thank you so much!