How to add data labels to a bar chart in Bokeh?
<p>In the Bokeh guide there are examples of various bar charts that can be created. <a href="http://bokeh.pydata.org/en/0.10.0/docs/user_guide/charts.html#id4" rel="nofollow">http://bokeh.pydata.org/en/0.10.0/docs/user_guide/charts.html#id4</a></p>

<p>This code will create one:</p>

<pre><code>from bokeh.charts import Bar, output_file, show
from bokeh.sampledata.autompg import autompg as df

p = Bar(df, 'cyl', values='mpg', title="Total MPG by CYL")

output_file("bar.html")

show(p)
</code></pre>

<p>My question is if it's possible to add data labels to each individual bar of the chart? I searched online but could not find a clear answer.</p>

<p>Ben Love excellent reply to this question. It worked like charm for me. I have been struggling around to plot bar chart where we were fetching the data inside the pandas dataframe. The code block I have used to plot the Bar Chart with x_range as labels below.</p>

<p>Stored labels inside the pandas dataframe. The key point here is that same x values been passed to the rect method and also to the x_range values. </p>

<pre><code>label = df['promotion_type'].tolist()
plot = Figure(x_range=label,plot_width=500, plot_height=500, toolbar_location="above",y_range=yr)
plot.rect(x='promotion_type',y='valuebytwo',source=source, width =0.5, height = 'value', legend=title)
</code></pre>

python bokeh