How to get exact height of Bar chart

I want to get the exact height of Bar graph at the top of each bar , how can I get it ?

Hey @Maverick06 ,

You can set textposition = "outside"

import plotly.graph_objects as go

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

fig = go.Figure(data=[go.Bar(
            x=x, y=y,
            text=y,
            textposition='outside',
        )])


fig.show()
2 Likes

Thanks @akroma for the reply but I am using plotly express

fig = px.bar(df_final, x='RCCA Owner', y='Count',color='Status',barmode='group')

How can I get the exact height through plotly express ?

1 Like

You can just update the traces:

fig.update_traces(textposition="outside")

You can find more options and examples here.

1 Like

Hey @Maverick06 ,

In addition to @jlfsjunior’s answer

You can try “text_auto” option.

plotly express bar doc:
https://plotly.com/python-api-reference/generated/plotly.express.bar

CODE:

import plotly.express as px

data_canada = px.data.gapminder().query("country == 'Canada'")

fig = px.bar(data_canada, x='year', y='pop', text_auto='pop')

fig.update_traces(textposition="outside")

fig.show()

Thanks @akroma , @jlfsjunior !