0

I have a problem with long xticks text. this my code.

fig = px.bar(dataa)
fig.update_layout(yaxis_title="Owners_Jurisdiction Count", xaxis_title="Owners")
fig.update_xaxes(tickangle=45, showgrid=True)
fig.show()

but what i got is the below picture: enter image description here

I want all long xticks text are truncated to 7 characters(for example)

2 Answers2

0

This question has been asked a few times before:

How to shorten and show only a part of text in plotly express axis?

Is it possible to limit or truncate the characters of the tick label in plotly?

Answer from first post:

To shorten the tick labels of your x-axis, you could either change the id's of your column beforehand by changing the dataframe, or you could use .update_layout() to change your tick labels afterwards.

Marshall K
  • 302
  • 1
  • 8
0

If the question is how to shorten the x-axis string to 7 characters because it is long, the x-axis ticks can be updated after drawing, so the list is set up using comprehension notation.

fig = px.bar(dataa)
fig.update_layout(yaxis_title="Owners_Jurisdiction Count", xaxis_title="Owners")
fig.update_traces(x=[x[:7] for x in df['Owners_name']])
fig.update_xaxes(tickangle=45, showgrid=True)
fig.show()
r-beginners
  • 31,170
  • 3
  • 14
  • 32