Make The Bar Chart Text Go Down A Line

Hi @Matan,

Plotly figures support markdown syntax <br> for line breaks, below is a workaround with using custom ticktext on axis.

import plotly.express as px

x = ['long label', 'very long label', 'extra super long label']
y= [10,50,15]

x_labels=[]
for label in x:
    x_labels.append(label.replace(' ','<br>'))
    
print(x_labels)

fig = px.bar(x=x, y=y)
fig.update_xaxes(tickvals=x, ticktext=x_labels)
fig.show()

2 Likes