Plotting data out of plotting boundaries

Hello All,

I would like to ask for you help with something that seems to be easy but I just cant find the answer.
I plotted an horizontal bar graph with text in the bars showing the actual value.
My problem is that the text goes beyond the border of the plotted area and disappears.
Is there any way to adjust the plotted area size to it will never cross its border?

image

Add a horizontal bar trace

fig1.add_trace(go.Bar(
    y=df_fig_with_format['Metrics'],
    x=df_fig['Var%'],
    orientation='h',
    marker_color=colors,
    name='Var%',
    text=[f"<b>{val:.0%}</b>" if metric.strip() not in ['',' ','   '] else "" for metric, val in zip(df_fig_with_format['Metrics'], df_fig['Var%'])],  # Add text labels conditionally
    textposition='outside',  # Position text outside bars
    
))

# Update layout for a more professional look
fig1.update_layout(
    title='Percent Variation',
    xaxis_title='%',
    xaxis=dict(
        tickformat='.0%',  # Format x-axis as integer percentage
        showgrid=True,  # Show grid lines
        gridcolor='lightgray',  # Grid color
        gridwidth=0.5  # Grid width
    ),
    yaxis=dict(
        tickfont_size=12,  # Font size for y-axis labels
        categoryorder='array',
        categoryarray=df_fig_with_format['Metrics'][::-1].tolist(),  # Reverse the order of metrics
        ticklabelposition="outside",  # positions the tick labels outside the axis line
    ),
    title_font_size=16,
    title_font_family='Arial',
    font=dict(color='black'),
    barmode='relative',
    bargap=0.1,
    plot_bgcolor='white',  # Background color of the plot
    margin=dict(l=0, r=0, t=50, b=50),  # Adjust margins
    width=500,  # Set the width of the plot (adjust as needed)
    height=700,
)

# Show the plot
fig1.show()

I found myself a solution.
Basically, just finding what is the range of the x axis and adding extra range.
xaxis=dict(range=[-abs(min(map(float, df_fig[β€˜Var%’]))*2 - max(map(float, df_fig[β€˜Var%’]))*0.25), max(map(float, df_fig[β€˜Var%’]))*1.25])

image

fig1 = go.Figure()

# Add a horizontal bar trace
fig1.add_trace(go.Bar(
    y=df_fig_with_format['Metrics'],
    x=df_fig['Var%'],
    orientation='h',
    marker_color=colors,
    name='Var%',
    text=[f"<b>{val:.0%}</b>" if metric.strip() not in ['',' ','   '] else "" for metric, val in zip(df_fig_with_format['Metrics'], df_fig['Var%'])],  # Add text labels conditionally
    textposition='outside',  # Position text outside bars
    
))

# Update layout for a more professional look
fig1.update_layout(
    title='Percent Variation',
    xaxis_title='%',
    xaxis=dict(
        tickformat='.0%',  # Format x-axis as integer percentage
        showgrid=True,  # Show grid lines
        gridcolor='lightgray',  # Grid color
        gridwidth=0.5,  # Grid width
        range=[-abs(min(map(float, df_fig['Var%']))*2 - max(map(float, df_fig['Var%']))*0.25), max(map(float, df_fig['Var%']))*1.25]
        
    ),

my inspiration came from this other post:
Text is cut-off in Plotly horizontal bar chart - Dash Python - Plotly Community Forum