# How to set DateTime format of xlabel using Makie

**URL:** <https://discourse.julialang.org/t/how-to-set-datetime-format-of-xlabel-using-makie/127397>\
**Category:** New to Julia\
**Tags:** makie\
**Created:** [March 27, 2025, 2:50am UTC](https://discourse.julialang.org/t/how-to-set-datetime-format-of-xlabel-using-makie/127397 "2025-03-27T02:50:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dk-zen](https://avatars.discourse-cdn.com/v4/letter/d/90db22/32.png) [@dk-zen](https://discourse.julialang.org/u/dk-zen)\
**Post date:** [March 27, 2025, 2:50am UTC](https://discourse.julialang.org/t/how-to-set-datetime-format-of-xlabel-using-makie/127397/1 "2025-03-27T02:50:40Z")

</div>

I want to get xlabel like “HH:MM”, Part of my code as follows. It doesn’t work as I want, but without throwing out an error. Anyone can give some suggestions?

```julia
fig = Figure(; size=(1000, 600))
ax1 = Axis(fig[1, 1], ylabel="H[nT]")
ax2 = Axis(fig[2, 1], ylabel="Z[nT]")

dates = DateTime("2025-03-19"):Hour(3):DateTime("2025-03-20")
tick_positions = datetime2unix.(dates) # Convert dates to Unix time (positions)
tick_labels = Dates.format.(dates, "HH:MM")  

ax3 = Axis(fig[3, 1],
    xlabel="Time_UT",
    ylabel="D[nT]",
    xticks = (tick_positions, tick_labels),
     yticklabelspace = 36.0 
 )
linkxaxes!(ax1, ax2, ax3)

lines!(ax1, df.time, df.H, color=:red)
hidexdecorations!(ax1, grid=false, label=false) 
lines!(ax2, df.time, df.Z, color=:red)
hidexdecorations!(ax2, grid=false, label=false) 
lines!(ax3, df.time, df.D, color=:red)

fig

```

The result is like this.

 ![image](https://global.discourse-cdn.com/julialang/original/3X/e/4/e4ba5c446a012ebe485a54ec9c109673407f6b79.png)

---

<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:** [March 27, 2025, 6:03am UTC](https://discourse.julialang.org/t/how-to-set-datetime-format-of-xlabel-using-makie/127397/2 "2025-03-27T06:03:33Z")

</div>

> <https://github.com/MakieOrg/Makie.jl/issues/3959>
>
> \`\`\`
> scatter(rand(Date(2000):Day(1):Date(2001), 100), rand(100); axis = (; xtick…s = Date(2000):Month(3):Date(2001)))
> \`\`\`
> 
> will not change the \`xticks\` at all - it appears that the argument is completely ignored (even feeding in obvious nonsense does not yield errors, the plot simply remains unchanged).

---

<div class="post-metadata">

**Author:** ![dk-zen](https://avatars.discourse-cdn.com/v4/letter/d/90db22/32.png) [@dk-zen](https://discourse.julialang.org/u/dk-zen)\
**Post date:** [March 27, 2025, 6:12am UTC](https://discourse.julialang.org/t/how-to-set-datetime-format-of-xlabel-using-makie/127397/3 "2025-03-27T06:12:46Z")

</div>

Thanks a lot! Your suggestion works.  
Makie cann’t support DateTime Type well. There is another way to avoid this issue, that is, transform DateTime data with datetime2unix function.

```julia
fig = Figure(; size=(1000, 600))

ax1 = Axis(fig[1, 1], ylabel="H[nT]")
ax2 = Axis(fig[2, 1], ylabel="Z[nT]")

dates = DateTime("2025-03-19"):Hour(3):DateTime("2025-03-20")
tick_positions = datetime2unix.(dates) # Convert dates to Unix time (positions)
# tick_labels = Dates.format.(dates)
tick_labels = ["$(Dates.format(t, "HH:MM") )\n $(Dates.format(t, "yyyy/mm/dd") )" for t in dates]

ax3 = Axis(fig[3, 1],
    xlabel="Time_UT",
    ylabel="D[nT]",
    xticks = (tick_positions, tick_labels),
    yticklabelspace = 36.0 
    # xticklabelrotation=pi / 4)
)
linkxaxes!(ax1, ax2, ax3)

lines!(ax1, datetime2unix.(df.time), df.H, color=:red)
hidexdecorations!(ax1, grid=false, label=false)  
lines!(ax2, datetime2unix.(df.time), df.Z, color=:red)
hidexdecorations!(ax2, grid=false, label=false) 
lines!(ax3, datetime2unix.(df.time), df.D, color=:red)

fig

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/d/b/db11d0230367da4c65c023e9681d2f8644825ef0.png)

---

<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:** [April 2, 2025, 9:19am UTC](https://discourse.julialang.org/t/how-to-set-datetime-format-of-xlabel-using-makie/127397/4 "2025-04-02T09:19:21Z")

</div>

Yes I think in practice the date support in Makie is currently only really useful for quick and dirty exploratory plotting.

While my comment in the GitHub issue can get you some of the way towards a more useable date format by at least letting you customise ticks, it doesn’t fix many other issues (e.g. date support being completely broken for some plot types).

Your solution of converting dates/datetimes to numerical values using `datetime2unix` and `date2epochdays` is the way to go in my view at this point.
