# Date tick formatting

**URL:** <https://community.plotly.com/t/date-tick-formatting/11081>\
**Category:** Dash Python\
**Created:** [June 21, 2018, 9:39am UTC](https://community.plotly.com/t/date-tick-formatting/11081 "2018-06-21T09:39:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rvsingh011](https://avatars.discourse-cdn.com/v4/letter/r/bb73d2/32.png) [@rvsingh011](https://community.plotly.com/u/rvsingh011)\
**Post date:** [June 21, 2018, 9:39am UTC](https://community.plotly.com/t/date-tick-formatting/11081/1 "2018-06-21T09:39:32Z")

</div>

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.

 ![image](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/c/c5b7328941b0b11e59f5267ded8bf83c48eb15c0.png)

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’  
}

---

<div class="post-metadata">

**Author:** ![rvsingh011](https://avatars.discourse-cdn.com/v4/letter/r/bb73d2/32.png) [@rvsingh011](https://community.plotly.com/u/rvsingh011)\
**Post date:** [June 22, 2018, 5:41am UTC](https://community.plotly.com/t/date-tick-formatting/11081/2 "2018-06-22T05:41:04Z")

</div>

@chriddyp please help

---

<div class="post-metadata">

**Author:** ![bcd](https://avatars.discourse-cdn.com/v4/letter/b/ec9cab/32.png) [@bcd](https://community.plotly.com/u/bcd)\
**Post date:** [June 22, 2018, 6:31am UTC](https://community.plotly.com/t/date-tick-formatting/11081/3 "2018-06-22T06:31:32Z")

</div>

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](https://plot.ly/python/reference/#layout-xaxis-nticks) 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.

---

<div class="post-metadata">

**Author:** ![David22](https://avatars.discourse-cdn.com/v4/letter/d/439d5e/32.png) [@David22](https://community.plotly.com/u/David22)\
**Post date:** [June 17, 2019, 4:19pm UTC](https://community.plotly.com/t/date-tick-formatting/11081/4 "2019-06-17T16:19:39Z")

</div>

@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

---

<div class="post-metadata">

**Author:** ![allenite](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@allenite](https://community.plotly.com/u/allenite)\
**Post date:** [June 18, 2020, 5:04am UTC](https://community.plotly.com/t/date-tick-formatting/11081/5 "2020-06-18T05:04:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![allenite](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@allenite](https://community.plotly.com/u/allenite)\
**Post date:** [June 18, 2020, 1:41pm UTC](https://community.plotly.com/t/date-tick-formatting/11081/6 "2020-06-18T13:41:24Z")

</div>

I found this in the documentation:

> **[Figure Reference](https://plotly.com/javascript/reference/#layout-xaxis-tickformatstops)**
>
> The extensive reference of plotly chart attributes for plotly.js.

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

So week ticks would be 7\*86400000.0
