Date tick formatting

Hi,
I am plotting a bar graph and passing the date as per the format on x axis. On Y axis I am plotting 4 bars per week and graph has 12 week data.
My problem is plotly don’t show all the values passed on x axis. 1 tick for 2 weeks is shown. Plus some bars are zero as well. It is really hard to see from where to where the tick belongs. Right Now my graph looks like this.

I want layout such that values are not skipped on x axis plus It can be easily seen these bars belong to this week. Either by kind of markers like this

|____________|
18-05-09

my graph layout right now is something like :
xaxis={
‘tickformat’: ‘%y/%m/%d’,
‘tickmode’: ‘array’,
‘tickangle’: ‘45’
}

@chriddyp please help

Hey @rvsingh011

It sounds like you are wanting something like:

xaxis = {
   'tickformat': '%Y-%m-%d',
   'tickmode': 'auto',
   'nticks': value, [where value is the max # of ticks]
   'tick0': value, [where value is the first tick]
   'dtick': value [where value is the step between ticks]
}

See here for reference. Also, a great way to quickly test these changes is to open the chart in the chart studio by clicking the ‘Edit in Chart Studio’ button in the modebar.

@rvsingh011,

Make sure your X data have a datetime format. If it’s not a datetime, then ‘tickformat’: ‘%Y-%m-%d’ won’t work.

If your original dataset include dates formatted as text, then convert it to datetime with
pd.to_datetime(db[‘Month’])

(Assuming you have a header “Month” in your dataset db)

Then, just proceed as suggested by @bcd

Hi bcd,

Can you clarify what we would use for the dtick value? Let’s say we want 7-day spacing. Would it be timedelta(days=7)? 7? Some other value? I can’t seem to get it to work with either of those values.

I found this in the documentation:


For example, to set the interval between ticks to one day, set dtick to 86400000.0

So week ticks would be 7*86400000.0

1 Like