# Linking subplot x-axes containing dates

**URL:** <https://discourse.julialang.org/t/linking-subplot-x-axes-containing-dates/61004>\
**Category:** New to Julia\
**Tags:** dates, plots\
**Created:** [May 12, 2021, 7:55am UTC](https://discourse.julialang.org/t/linking-subplot-x-axes-containing-dates/61004 "2021-05-12T07:55:57Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![goosst](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goosst/32/19090_2.png) [@goosst](https://discourse.julialang.org/u/goosst)\
**Post date:** [May 17, 2021, 6:23pm UTC](https://discourse.julialang.org/t/linking-subplot-x-axes-containing-dates/61004/6 "2021-05-17T18:23:07Z")

</div>

sorry but I just feel stupid trying to plot this, tried to use your approach on my data with ZoneDateTime (the original data), converting to DateTime (similar as your example). But my plots just look all the same without decently linked x-axis. In matlab this normally takes me 2 minutes ☹ .

> It is recommended to provide a MWE as per [guidelines](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757).

Sure, however I can’t upload attachments here. I’ve added a small dataset here: [http://users.telenet.be/goosst/data.jld](http://users.telenet.be/goosst/data.jld).  
I saved this file in this way:  
` using JLD save("data.jld","timestamps",timestamps,"pressure",pressure,"timestamps2",timestamps2,"waterdepth",waterdepth)`

thanks!

```julia
# plotting with zonedatetime
plot_water=plot(Dates.format.(timestamps2,"dd-HH:MM"),waterdepth, xrotation = 60, label="water depth",lw = 3)
plot_pressure=plot(Dates.format.(timestamps,"dd-HH:MM"),pressure,xrotation = 60,label="baro pressure", lw = 3,color=:red)
plot_merged=plot(plot_water,plot_pressure,layout = (2, 1),link=:x,xticks=10)

# using datetime instead of zonedatetime
timestamps_dt=DateTime[];
for i = 1:length(timestamps)
    push!(timestamps_dt,DateTime(timestamps[i]))
end

timestamps2_dt=DateTime[];
for i = 1:length(timestamps2)
    push!(timestamps2_dt,DateTime(timestamps2[i]))
end

plot_water=plot(Dates.format.(timestamps2_dt,"dd-HH:MM"),waterdepth, xrotation = 60, label="water depth",lw = 3)
Plots.plot!(xticks=(timestamps2_dt, Dates.format.(timestamps2_dt,"dd-HH:MM")))

plot_pressure=plot(Dates.format.(timestamps_dt,"dd-HH:MM"),pressure,xrotation = 60,label="baro pressure", lw = 3,color=:red)
Plots.plot!(xticks=(timestamps_dt, Dates.format.(timestamps_dt,"dd-HH:MM")))

plot_merged=plot(plot_water,plot_pressure,layout = (2, 1),link=:x,xticks=10)

```

---

_[View the full topic](https://discourse.julialang.org/t/linking-subplot-x-axes-containing-dates/61004)._
