Makie: Histogram of DateTime values

How can you plot a histogram of datetimes with Makie? There is mention of axis-based unit conversions in the Makie documentation by setting the dim1_conversion or dim2_conversion attributes to Makie.DateTimeConversion(), but it didn’t seem to work for histograms.

datetimes = collect(DateTime(2023):Day(1):DateTime(2025))
hist(datetimes)

You can’t, the support for dates is not working very well which is known to devs and being worked on.

Your best bet is just doing the conversion yourself:

hist(Dates.datetime2epochms.(datetimes),
 axis = (; xtickformat = x -> string.(Dates.epochms2datetime.(x)), xticklabelrotation = π/5)
)
1 Like

I spoke to soon:

You can try with that PR if you want

That PR doesn’t seem relevant tbh…

In general, @elipivo, unitful & datetime support in Makie is spotty. Fine when it works, but often it doesn’t. Convert everything to plain numbers when passing to plotting functions to always be certain, eg following @nilshg suggestion above.