# Plots... with Dates along abscissa axis?

**URL:** <https://discourse.julialang.org/t/plots-with-dates-along-abscissa-axis/24454>\
**Category:** Visualization\
**Created:** [May 21, 2019, 10:18pm UTC](https://discourse.julialang.org/t/plots-with-dates-along-abscissa-axis/24454 "2019-05-21T22:18:51Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [May 21, 2019, 10:18pm UTC](https://discourse.julialang.org/t/plots-with-dates-along-abscissa-axis/24454/1 "2019-05-21T22:18:51Z")

</div>

I have some data where I want to plot some quantity (ordinate) against dates (abscissa). The abscissa data are in `Dates.Date()` format. When plotting (I tested Plots with unicodeplots back-end), the dates are given in seconds (I guess), and not in year-month-day.

Is there a way to specify that I want the time in year-month-day format? If so, can I specify the interval along the axis? [E.g., only the dates that occur in the data, or, say every 2 weeks?]

---

<div class="post-metadata">

**Author:** ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)\
**Post date:** [May 21, 2019, 11:29pm UTC](https://discourse.julialang.org/t/plots-with-dates-along-abscissa-axis/24454/2 "2019-05-21T23:29:50Z")

</div>

I can’t help with Plots.jl, but [VegaLite.jl](https://github.com/fredo-dedup/VegaLite.jl) has pretty comprehensive support for time scales. I think the combination of the docs there and the original [vega-lite docs](https://vega.github.io/vega-lite/) should have enough info on that feature to make it work.

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [May 22, 2019, 12:10am UTC](https://discourse.julialang.org/t/plots-with-dates-along-abscissa-axis/24454/3 "2019-05-22T00:10:57Z")

</div>

Also, see these examples by [GMT](https://www.generic-mapping-tools.org/GMT.jl/latest/frames/#Cartesian-time-axes-1)

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [May 22, 2019, 8:56am UTC](https://discourse.julialang.org/t/plots-with-dates-along-abscissa-axis/24454/4 "2019-05-22T08:56:57Z")

</div>

It’s supposed to be automatic in Plots - showing it in seconds would be a bug, but could also be a limitation of the unicodeplots backend. You can always format the x axis yourself by passing a function specifying what you want to the `xformatter` argument.

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [May 22, 2019, 9:22am UTC](https://discourse.julialang.org/t/plots-with-dates-along-abscissa-axis/24454/5 "2019-05-22T09:22:27Z")

</div>

Hm… seems like the problem lies with the UnicodePlots backend:

- The data:  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/5/3/530aaa5f6ad6edb915fc5dabae2fed86315e0334.png)
- The plot using UnicodePlots as backend:  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/9/8/98f2ac286b628ef0adedf340343075633d9672cb.png)
- With PyPlot as backend:  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/5/f/5f00d90bf1f82c348428bbd9ffc86b47063b6217.png)

---

<div class="post-metadata">

**Author:** ![JosephPollacco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josephpollacco/32/51404_2.png) [@JosephPollacco](https://discourse.julialang.org/u/JosephPollacco)\
**Post date:** [October 1, 2020, 7:18am UTC](https://discourse.julialang.org/t/plots-with-dates-along-abscissa-axis/24454/6 "2020-10-01T07:18:49Z")

</div>

Here is my solution:

```julia
			using Plots.PlotMeasures, LaTeXStrings
				using Plots;pgfplotsx()
				using Dates

         DateTick=Date[1]:Day(30):Date[N_Climate]
         DateTick2= Dates.format.(DateTick, "d u Y")

	Plot1=Plots.plot(layout=1)
	Plots.plot!(Plot1, clim.Date[1:clim.N_Climate], clim.Pet[1:clim.N_Climate])

      Plots.plot!(Plot1, xticks=(DateTick, DateTick2), xrotation=rad2deg(pi/3), framestyle = :origin)

```

---

<div class="post-metadata">

**Author:** ![JosephPollacco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josephpollacco/32/51404_2.png) [@JosephPollacco](https://discourse.julialang.org/u/JosephPollacco)\
**Post date:** [October 1, 2020, 7:22am UTC](https://discourse.julialang.org/t/plots-with-dates-along-abscissa-axis/24454/7 "2020-10-01T07:22:32Z")

</div>

![WAITOA_Plot_RainfallInterception_100](https://global.discourse-cdn.com/julialang/original/3X/f/1/f1f141a41d510a44a1bcaf20393a30df2c04650a.png)

---

<div class="post-metadata">

**Author:** ![dires](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@dires](https://discourse.julialang.org/u/dires)\
**Post date:** [March 19, 2021, 8:52am UTC](https://discourse.julialang.org/t/plots-with-dates-along-abscissa-axis/24454/8 "2021-03-19T08:52:31Z")

</div>

Hay  
I am using Godfly for my plots .and I want to represent the X-axis with months, the result I want to show in the plot is one-year data with an hourly resolution, and I want to represent the x-axis in terms of months that hours.
