Reputation: 1
enter image description hereIm a beginner in programming with Python and I need your help!
Im trying to put the value of the bars on top or above them depending on their position on the y-axis. In the plus side of the y-axis I want to put the values above the bars and in the minus side, I want to out the values under the bars.
Im also trying to put the labels of the bars on top of the graph in the same color as the bars.
NEW:
ax.1+plt.bar(r, elements,color=bar_colors,edgecolor='none',width=bardWidth) ax=dataset.plot(width=5.0,kind='bar',y=dataset.columns,figsize=(6,5),zorder=3)
for p in ax.patches: ax.annotate("%.2f"%p.get.height(),(p.get_x()+p.get.width()/2.,p.get_height()),ha='center',va='center',xytext=(0,10),textcoords='offsetpoints')
Upvotes: 0
Views: 262
Reputation: 13349
Are you looking for something like this. If yes then try to use ax.patches
to put value on the bar graph.
df:
a b c d
0 66 92 98 17
1 -83 57 86 97
2 96 47 -73 32
ax = df.plot(width=0.8, kind='bar',y=df.columns,figsize=(10,5))
for p in ax.patches:
ax.annotate(str(round(p.get_height(),2)), (p.get_x() * 1.005, p.get_height() * 1.01),color='black')
ax.axes.get_yaxis().set_ticks([])
Upvotes: 0