Closed
Description
I was trying to create annotations for grouped bar charts - where each bar has a specific data label.
An example is as follows: https://plot.ly/~ashish.baghudana/49.embed
However, as you see the data labels are not centered individually, but overall. I was wondering if there is a workaround to this, rather than annotating manually.
Appreciate the help!
The code itself is a simple modification of the examples in tutorial.
import plotly.plotly as py
import plotly.graph_objs as go
x = ['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 + annotations2
trace1 = 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')Metadata
Metadata
Assignees
Labels
No labels

Activity
chriddyp commentedon Nov 24, 2015
Thanks for reporting @ashishbaghudana ! There isn't a good workaround right now. Could you re-open this issue in the plotly.js repo? Once better support gets added there, it'll be available in here in python.
aleburato commentedon Jul 28, 2016
I might have found a decent workaround (I use the JS library but, you get the point):
tarunparmar commentedon Aug 8, 2017
Is there any workaround for this in R ?
salim-b commentedon Nov 22, 2018
By now it's properly supported, just set textposition.
GeorgeFlorian commentedon Mar 29, 2023
This hasn't been fixed/added.
textpositionapplies only to thetextproperties of each trace andannotationsrepresent alayoutproperty.