Individuell beschriftete Balken für Balkendiagramm in Plotly

Ich habe versucht, Anmerkungen für gruppierte Balkendiagramme zu erstellen. Dabei hat jeder Balken eine bestimmte Datenbeschriftung, die den Wert dieses Balkens anzeigt und sich über der Mitte des Balkens befindet.

Ich habe versucht, die Beispiele im Tutorial wie folgt zu ändern:

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')

Welche diese Handlung produziert:https: //plot.ly/~ashish.baghudana/49.embe

Die Datenbeschriftungen werden jedoch nicht über einzelnen Balken, sondern über der Mitte jedes @ zentrierGrupp von Bars. Ich habe mich gefragt, ob es eine Problemumgehung gibt, anstatt manuell Anmerkungen zu machen.

Antworten auf die Frage(4)

Ihre Antwort auf die Frage