I was trying to create annotations for grouped bar charts - where each bar has a specific data label that shows the value of that bar and is located above the centre of the bar.
I tried a simple modification of the examples in tutorial to achieve this, as follows:
import plotly.plotly as py
import plotly.graph_objs as gox = ['Product A', 'Product B', 'Product C']
y1 = [20, 14, 23]
y2 = [12, 18, 29]annotations1 = [dict(x=xi,y=yi,text=str(yi),xanchor='auto',yanchor='bottom',showarrow=False,) for xi, yi in zip(x, y1)]
annotations2 = [dict(x=xi,y=yi,text=str(yi),xanchor='auto',yanchor='bottom',showarrow=False,) for xi, yi in zip(x, y2)]
annotations = annotations1 + annotations2trace1 = go.Bar(x=x,y=y1,name='SF Zoo'
)
trace2 = go.Bar(x=x,y=y2,name='LA Zoo'
)
data = [trace1, trace2]
layout = go.Layout(barmode='group',annotations=annotations
)
fig = go.Figure(data=data, layout=layout)
plot_url = py.plot(fig, filename='stacked-bar')
Which produces this plot: https://plot.ly/~ashish.baghudana/49.embed
However,the data labels are not centred over individual bars, but over the centre of each group of bars. I was wondering if there is a workaround to this, rather than annotating manually.