I have a subplot bar chart coded as:
axes = df.plot.bar(yerr=df1, figsize=(10,8), legend=False,
title='Bar chart',grid=1, subplots=True, layout (5,1),xticks=None)
Is there an easy way to modify the code so that to see numerical values from dataframe df on the top of each bar?
UPDATE: with the code below still no values:
df = DataFrame(np.zeros((5, 3)))
df.index=['[1,3)','[3, 4)','[4, 5)','[5, 6)','[7]']
df.columns=['cat1','cat2','cat3']
df.iloc[0,:]= np.array( [0.4, 0.3, 0.2])
df.iloc[1,:]= np.array( [0, 0.1, 0.9])
df.iloc[2,:]= np.array( [0.3, 0.1, 0.3])
df.iloc[3,:]= np.array( [0, 0, 0.2])
df.iloc[4,:]= np.array( [0.0, 0, 0.9])
se_df = DataFrame(np.zeros((5, 3)))
se_df.index=['[1,3)','[3, 4)','[4, 5)','[5, 6)','[7]']
se_df.columns=['cat1','cat2','cat3']
se_df.iloc[0,:]= np.array( [0.1, 0.2, 0.002])
se_df.iloc[1,:]= np.array( [0.003, 0.02, 0.008])
se_df.iloc[2,:]= np.array( [0.006, 0.03, 0.0002])
se_df.iloc[3,:]= np.array( [0.001, 0, 0.0001])
se_df.iloc[4,:]= np.array( [0.0001, 0, 0.0002])
df1=df.transpose()
se_df1=se_df.transpose()
axes = df1.plot.bar(yerr=se_df1, figsize=(10,8), legend=False,
title='Title',grid=1, subplots=True, layout=(5,1),xticks=None)
for n,i in enumerate(axes, 1):
for rec, label in zip(i.patches,df.loc[:, n].astype(str)):
height = rec.get_height()
i.text(rec.get_x() + rec.get_width() / 2, height - 5, label,
ha = 'center', va='bottom', color='w', weight='bold')
plt.tight_layout()
Could you please indicate what am I doing wrong?