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
JavaScript
x
18
18
1
filtered_data = df[df["Year"] == 2017]
2
display_texts = filtered_data["column_name"].tolist()
3
4
fig = px.bar(
5
filtered_data,
6
x="x_column",
7
y="y_column",
8
color="color",
9
title="some title",
10
)
11
12
fig.update_traces(
13
texttemplate=display_texts,
14
textposition="outside",
15
)
16
fig.update_layout(showlegend=False)
17
fig.update_layout(autosize=False, width=1800, height=600)
18
Advertisement
Answer
You should remove texttemplate=display_texts
and add text=display_texts
to px.bar
.