# Makie: Histogram of DateTime values

**URL:** <https://discourse.julialang.org/t/makie-histogram-of-datetime-values/130779>\
**Category:** General Usage\
**Tags:** question, plotting, makie\
**Created:** [July 16, 2025, 2:01pm UTC](https://discourse.julialang.org/t/makie-histogram-of-datetime-values/130779 "2025-07-16T14:01:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![elipivo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elipivo/32/32916_2.png) [@elipivo](https://discourse.julialang.org/u/elipivo)\
**Post date:** [July 16, 2025, 2:01pm UTC](https://discourse.julialang.org/t/makie-histogram-of-datetime-values/130779/1 "2025-07-16T14:01:58Z")

</div>

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.

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

```

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [July 16, 2025, 2:06pm UTC](https://discourse.julialang.org/t/makie-histogram-of-datetime-values/130779/2 "2025-07-16T14:06:13Z")

</div>

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:

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

```

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [July 17, 2025, 9:51am UTC](https://discourse.julialang.org/t/makie-histogram-of-datetime-values/130779/3 "2025-07-17T09:51:40Z")

</div>

I spoke to soon:

> <https://github.com/MakieOrg/Makie.jl/pull/5159>
>
> This PR changes the way that ticks for datetime axes are located and formatted b…y default. The new tick formatting reduces the amount of redundant information by printing time on a separate line from date (if time is different from 0). This way, the date only has to be shown whenever it changes from tick to tick. Similarly, only the time component of the tick step size is usually shown, unless there's a step in the parent component. For example, seconds would be shown \`:58\`, \`:59\` but then as the minute changes, the full time is shown like \`03:17:00\` and then further \`:01\`, \`:02\`, etc.
> 
> Fixes https://github.com/MakieOrg/Makie.jl/issues/4404, fixes https://github.com/MakieOrg/Makie.jl/issues/3972, fixes https://github.com/MakieOrg/Makie.jl/issues/3959
> 
> \## This PR
> 
> \`\`\`julia
> f = Figure(size = (600, 800))
> data = cumsum(randn(12))
> for (i, T) in enumerate(\[Year, Month, Day, Hour, Minute, Second, Millisecond\])
> times = DateTime(2025, 06, 30, 17, 54, 56, 993) .+ T.(1:12)
> lines(f\[i, 1\], times, data)
> Label(f\[i, 2\], "$T", rotation = pi/2, font = :bold, tellheight = false)
> end
> f
> \`\`\`
> 
> \<img width="712" alt="image" src="https://github.com/user-attachments/assets/4dd14a28-b559-4d88-8f5a-7536370b282a" /\>
> 
> \## Master
> 
> \<img width="712" alt="image" src="https://github.com/user-attachments/assets/2c54bf43-c18f-4b4c-b672-c2e7cd2c63aa" /\>
> 
> 
> This PR also adds a separate dispatch route for datetime ticks which fixes the bug that the ticks or the tick format could not be changed manually and were always hardcoded to the automatic tick finding algorithm. 
> 
> \`\`\`julia
> dates = Date(2025, 06, 30) .+ Day.(1:5)
> data = cumsum(randn(5))
> 
> with\_theme(Axis = (; yticksvisible = false, yticklabelsvisible = false, ygridvisible = false)) do
> f = Figure()
> lines(f\[1, 1\], dates, data)
> lines(f\[2, 1\], dates, data; axis = (; xticks = (dates\[\[1, 2, 3, 5\]\], \["A", "B", "C", "E"\])))
> lines(f\[3, 1\], dates, data; axis = (; xtickformat = "e, d.m.yyyy"))
> f
> end
> \`\`\`
> 
> \<img width="712" alt="image" src="https://github.com/user-attachments/assets/eae3070b-b389-4982-9bea-f4d070abd646" /\>

You can try with that PR if you want

---

<div class="post-metadata">

**Author:** ![aplavin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aplavin/32/222056_2.png) [@aplavin](https://discourse.julialang.org/u/aplavin)\
**Post date:** [July 17, 2025, 3:32pm UTC](https://discourse.julialang.org/t/makie-histogram-of-datetime-values/130779/4 "2025-07-17T15:32:04Z")

</div>

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.
