'Plotly Text Annotation shows the same text throughout
I am trying to show the text on the bars based on some filtered data but the text shows the same value for the last item in the list. I can't seem to find out what the issue is because display_texts itself gives me what I expect
filtered_data = df[df["Year"] == 2017]
display_texts = filtered_data["column_name"].tolist()
fig = px.bar(
filtered_data,
x="x_column",
y="y_column",
color="color",
title="some title",
)
fig.update_traces(
texttemplate=display_texts,
textposition="outside",
)
fig.update_layout(showlegend=False)
fig.update_layout(autosize=False, width=1800, height=600)
Solution 1:[1]
You should remove texttemplate=display_texts and add text=display_texts to px.bar.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Phoenix |

