Time tick issue on x-axis

Here’s a quick solution (probably can be improved on). It will work with DateTime or Time types:

import Cairo
using Dates, Gadfly

halfhour(x) = hour.(x) + (minute.(x).>30)*0.5

n = 1000
date1 = DateTime(2018,1,1) + Hour.(rand(0:23, n)) + Minute.(rand(0:59, n)) + Second.(rand(0:59,n))
time1 = Time.(date1) 

xticks = Guide.xticks(ticks=[0:2:24;])
pa = plot(x=halfhour.(date1), Geom.histogram(bincount=48), xticks)
pb = plot(x=halfhour.(time1), Geom.histogram(bincount=48), xticks)
draw(PNG(8inch,4inch), hstack(pa, pb))
1 Like