How can I resize labels which are very long

I am creating a chart in python/Jupyter notebook

data = [
go.Bar(
y=[‘Apples’, ‘Oranges’, ‘WatermelonWatermelonWatermelonWatermelonWatermelonWatermelonWatermelon’, ‘Pears’],
x=[3, 2, 1, 4], orientation=‘h’
)
]

offline.iplot(data)

How can I display the string ‘Watermelonwater…’ I want to display the entire string - it’s fine if it is wrapped.

1 Like

You can increase the left margin to show long label.

layout = go.Layout(
    margin=go.layout.Margin(
        l=500
    )
)

fig = go.Figure(data=data, layout=layout)
plotly.offline.iplot(fig, filename='basic-bar')
1 Like

Do you know if I can wrap text?

It also seems like the text should be truncated on the right. It is now truncated on the left.

Hi @nilanjenator, you can, and also you can adjust the margin, for example:

data = [
   go.Bar(
       y=['Apples', 'Oranges', 'Watermelon<br>Watermelon<br>Watermelon', 'Pears'],
       x=[3, 2, 1, 4], orientation='h'
   )]

layout = go.Layout(
   margin=go.layout.Margin(
       l=100
   )
)

fig = go.Figure(data=data, layout=layout)
plotly.offline.iplot(fig)

2 Likes

Thanks,
I was actually looking for automatic wrapping of long labels

I have been facing similar issue with Plotly Express, Bar Chart. Is there any solution like, go.layout() option?

1 Like

Any updated on word wrapping for labels ?

I had the same problem and used ChatGPT to solve this:

Wrap tick labels after 15 characters
# Ticklabels wrap
fig.update_layout(xaxis={‘tickmode’: ‘array’,
‘tickvals’: df.index,
‘ticktext’: [txt[:15] + ‘
’ + txt[15:] if len(txt) > 15 else txt for txt in fig[‘layout’][‘xaxis’][‘categoryarray’]]})

Wrap tick labels after 15 characters at the next whitespace and set tickangle
# Ticklabels umbruchen
fig.update_layout(xaxis={‘tickmode’: ‘array’,
‘tickvals’: df.index,
‘ticktext’: [txt[:15] + ‘
’ + txt[15:] if len(txt) > 15 else txt for txt in fig[‘layout’][‘xaxis’][‘categoryarray’]]})