Bar width using Plotly express

Is there a way to set the width of each bar, or all bars using plotly.express?

The working examples I managed to found people were using graph.object. I just donโ€™t want rewrite my code.

1 Like

Hi @guilhermeely,

This is how you can do it

import plotly.express as px
data_canada = px.data.gapminder().query("country == 'Canada'")
fig = px.bar(data_canada, x='year', y='pop')
fig.update_traces(width=1)
fig.show()

before updating figure:

after updating figure:

You should also have a look at the documentation, there are plenty of examples there:

hope this helps, Alex -

5 Likes

Thanks for the response.

Already tried that, the bars disappears if I do that.

1 Like

maybe you have set the width parameter too low, if you donโ€™t provide any data I cannot help you further

Br, Alex

For the benefit of others landing on this page: when using the date type on the X axis the width units appear to be milliseconds.

2 Likes

how can I force a specific bar width across all my figure?
I donโ€™t want to write fig.update_traces(width=1) every time.

take the width in range between 0 and 1,it will work