0

I would like to adjust the labels so they are on top of each bar corresponding with the correct data from another column in the dataframe. The bar graph that is plotted are the values in the ['MIROC','CCMS4','CRMN'], but I want to label each bar with the values from the ['prec_dry','prec_avg','perc_wet'] columns.

fig, ax = figsize=(20, 10)
ax = Filter_df.plot.bar(y = ['MIROC','CCMS4','CRMN'],rot=0)

for (c,p,d), i in zip(Filter_df[['prec_dry','prec_avg','perc_wet']].values, ax.patches):
ax.text(i.get_x(),i.get_height(),
        f" {c }{ p}{ d}", fontsize=10)

Here is my dataframe:

Forecasts CCMS4   perc_avg  MIROC perc_dry  CRMN  perc_wet
c14d0fr    0.007    97.9%   0.002   99.5%   0.002   99.6%
d30n0fr    0.038    94.2%   0.045   98.5%   0.024   98.3%
pv8mfr     0.010    98.3%   0.002   99.7%   0.002   99.8%

enter image description here

  • 1
    Update your version of matplotlib and research [`bar_label`](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.bar_label.html) perhaps. – BigBen Jun 02 '22 at 17:10

0 Answers0