i have a code like that
import plotly.express as px
df = px.data.gapminder().query("continent == 'Europe' and year == 2007 and pop > 2.e6")
fig = px.bar(df, y='pop', x='country', text='pop')
fig.update_traces(texttemplate='%{text:.2s}', textposition='outside')
fig.update_layout(uniformtext_minsize=8, uniformtext_mode='hide')
fig.show()
how to make max length on colums name?
I think there is a very similar question & answer here. Adapted to your case, you could chose to keep only the first n letters of the column name. It would look like the following:
import plotly.express as px
# Data
df = px.data.gapminder().query("continent == 'Europe' and year == 2007 and pop > 2.e6")
# Figure
fig = px.bar(df, y='pop', x='country', text='pop')
fig.update_traces(texttemplate='%{text:.2s}', textposition='outside')
fig.update_layout(uniformtext_minsize=8, uniformtext_mode='hide')
# The modification: overwrite tick labels
# Choose the number of letters to keep
n = 7
fig.update_layout(
xaxis = {
'tickmode': 'array',
'tickvals': df.country.unique().tolist(),
'ticktext': [i[:n] for i in df.country.unique().tolist()],
}
)
fig.show()