Fully display the amount in horizontal bar chart

Hi,

With fig.update_traces(textposition="outside", textangle=0 ), chart plus text over the background will not able to fully display.

With fig.update_traces(textposition="inside", textangle=0 ), chart too short will not fully display the text amount as well.

So, is there any way to make it win-win situation?

fig = px.bar(pie_bar_gp, x='Amount', y='Product', title='Pie-Bar' ,orientation='h' 
                ,text='Amount', text_auto=",.2f"
                )      
    

    fig.update_layout(barmode="group")
    fig.update_layout({
          'paper_bgcolor': 'rgba(0, 0, 0, 0)',
        })

chart with:

    fig.update_traces(textposition="inside", textangle=0 )



 fig.update_traces(textposition="outside", textangle=0 )

Hi,

I would just increase the x-axis range slightly.

EDIT:

import numpy as np
import plotly.express as px

# create y values
y = np.exp2(np.arange(10))

# create figure, expand decimals to make the text too large to fit in figure with auto x-range 
fig=px.bar(x=y, orientation='h', text=y, text_auto=",.8f")
fig.update_layout({'height':900, 'xaxis':{'range':[0, y.max()*1.1]}})
fig.update_traces(textposition="outside", textangle=0)
2 Likes