Bar chart shrink to a line when there is only one bar

Hello everyone!
I’ve got a bar chart with tick0 and range of week.
When there is only one bar it shrinks to a line like this:


(On 01/11)
Any ideas?

Hello @Karnishitrit,

Could you please provide an MRE of what you have?

It’s hard to say without seeing your data and code.

Hi @jinnyzor
My code is on another network so I can’t give a mre

@AIMPED,

Any thoughts on this?

@Karnishitrit,

Which bar chart are you using? PX or GO?

Hi!

This usually happens, if the x-range is quite large, this would be my guess.

An example with 700 days on the x- axis- there is literally no space to draw the columns much wider.

import pandas as pd
import plotly.express as px

# create data
week = pd.date_range('01/01/2022', periods=700, freq='D')
value = [0 for _ in range(700)]
value[155] = 60

# create DataFrame
df  = pd.DataFrame({'date': week, 'value': value})

# create figure
fig = px.bar(df, x='date', y='value')

fig.show()

which creates:

EDIT:

If you change the axis range to one week you get this:

fig.update_xaxes({'range':[df.date.iloc[154], df.date.iloc[161]]})

1 Like

It’s go @jinnyzor

I have only 7 days on the x-axis (of the last week)
And one bar in it

Hi @Karnishitrit

Are you sure, that the x-axis are actually days? What does your data look like? What happens, if you create dummy values for the rest of the days, how does it look like then?

Did you try running my example on your system? Does it look like the images I attached here?

Without more information and the code which creates your figure it will be difficult to help you, I guess.