Is it possible to add custom text to bar chart text within the bar?

Hello,

I have a data frame with 3 columns, index, name, and value. I made a bar chart exact like this:

df = px.data.medals_long()

fig = px.bar(df, x="medal", y="count", color="nation", text_auto=True)
fig.show()

Text auto works fine and it shows me the values within each bar. Now since it only show me the values in plain number I want to add text like dollar so that it shows me 343 dollar in the bar chart. Is that possible?

Hey @Gobrel ,

Try this:

import plotly.graph_objects as go

x = ['Product A', 'Product B', 'Product C']
y = [20, 14, 23]

# Use textposition='auto' for direct text
fig = go.Figure(data=[go.Bar(
            x=x, y=y,
            text=[str(i)+' Dollar' for i in y],
            textposition='auto',
        )])

fig.show()

Have a nice day.

1 Like