# Gnuplot.jl: Datetime in xtics

**URL:** <https://discourse.julialang.org/t/gnuplot-jl-datetime-in-xtics/65281>\
**Category:** Visualization\
**Tags:** gnuplot\
**Created:** [July 25, 2021, 10:14pm UTC](https://discourse.julialang.org/t/gnuplot-jl-datetime-in-xtics/65281 "2021-07-25T22:14:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Inna](https://avatars.discourse-cdn.com/v4/letter/i/8e8cbc/32.png) [@Inna](https://discourse.julialang.org/u/Inna)\
**Post date:** [July 25, 2021, 10:14pm UTC](https://discourse.julialang.org/t/gnuplot-jl-datetime-in-xtics/65281/1 "2021-07-25T22:14:53Z")

</div>

Hello everyone,  
I have timeseries and i want to have on xtics Datetime format.  
my data is called `array`:

```julia
 1980 1 111.439 1980-01-01 1                                                                                        
 1980 2 111.255 1980-02-01 2                                                                                        
 1980 3 111.159 1980-03-01 3                                                                                        
    ⋮                                                                                                                      
 2019 10 109.153 2019-10-01 478                                                                                        
 2019 11 108.969 2019-11-01 479                                                                                        
 2019 12 108.689 2019-12-01 480

```

when i code this

```julia
@gp 1:480 array[:,3] " w lp pt 7 lc 'black' notit "
@gp :- "set xtics ('1980' 1, '1985' $(5*12), '1990' $(10*12),'1995' $(15*12),'2000' $(20*12),'2005' $(25*12),'2010' $(30*12),'2015' $(35*12)) font ',25'" 

```

i get this:

 ![j2](https://global.discourse-cdn.com/julialang/original/3X/7/b/7bb6e673f785c9eea0d94a3ce848a182ae063ecb.png)

However i want an easier way to define my xticlabels, so i code this :

```julia
@gp "set xdata time" "set timefmt '%Y-%m-%d' " "set format x '%Y'" "set xrange ['1980-01-01' : '2019-12-01']"
@gp :- "plot 'array.txt' u 4:3 w lp pt 7 lc 'black' notit "
@gp :- "set xtics '1980-01-01', 4*12*2629746, '2019-12-01' font ',25'" 

```

that give me this:

 ![j1](https://global.discourse-cdn.com/julialang/original/3X/c/5/c56f9f16d9b4e5331b94bb1061a5aa50741e3590.png)

this (second) way is better to define easier my xticlabels, BUT i have to write my array firstly and then ploting it. `"set xtics '1980-01-01', 4*12*2629746, '2019-12-01' font ',25'" ` means that the xticlabels displayed per 4 years (4\*12).

I am wondering if i can avoid the writing of the array with this way:

```julia
@gp "set xdata time" "set timefmt '%Y-%m-%d' " "set format x '%Y'" "set xrange ['1980-01-01' : '2019-12-01']"
@gp :- string.(Array[:,4]) Float64.(Array[:,3]) " w lp pt 7 lc 'black' notit "

```

however i get this error:

```julia
┌ Error:                                                                                                                   
│                                                                                                                          
│ gnuplot> plot $data1 w lp pt 7 lc 'black' notit                                                                      
│ ^                                                                     
│ line 13020: Need full using spec for x time data                                                                
└ @ Gnuplot C:\Users\ms\.julia\packages\Gnuplot\jJ4hs\src\Gnuplot.jl:908                                                   
ERROR: Gnuplot error: ["Need full using spec for x time data"]                                                             
Stacktrace:                                                                                                                
 [1] error(s::String)                                                                                                      
   @ Base .\error.jl:33                                                                                                    
 [2] gpexec(gp::Gnuplot.GPSession, command::String)                                                                        
   @ Gnuplot C:\Users\ms\.julia\packages\Gnuplot\jJ4hs\src\Gnuplot.jl:911                                                  
 [3] execall(gp::Gnuplot.GPSession; term::String, output::String)                                                          
   @ Gnuplot C:\Users\ms\.julia\packages\Gnuplot\jJ4hs\src\Gnuplot.jl:940                                                  
 [4] execall                                                                                                               
   @ C:\Users\ms\.julia\packages\Gnuplot\jJ4hs\src\Gnuplot.jl:921 [inlined]                                                
 [5] driver(::Symbol, ::Vararg{Any, N} where N; is3d::Bool)                                                                
   @ Gnuplot C:\Users\ms\.julia\packages\Gnuplot\jJ4hs\src\Gnuplot.jl:1336                                                 
 [6] driver(::Symbol, ::Vararg{Any, N} where N)                                                                            
   @ Gnuplot C:\Users\ms\.julia\packages\Gnuplot\jJ4hs\src\Gnuplot.jl:1262                                                 
 [7] top-level scope                                                                                                       
   @ REPL[195]:1 

```

I do not understand `Need full using spec for x time data` can you help me please ???  
when i code

```julia
@gp "set xdata time" "set timefmt '%Y-%m-%d' " "set format x '%Y'" "set xrange ['1980-01-01' : '2019-12-01']"
@gp :- string.(Array[:,4]) Float64.(Array[:,3]) "u 1:2 w lp pt 7 lc 'black' notit "

```

i get this :

```julia
┌ Error:                                                                                                                   
│ line 20716: warning: Skipping data file with no valid points                                                    
│                                                                                                                          
│ gnuplot> plot $data1 u 1:2 w lp pt 7 lc 'black' notit                                                                
│ ^                                                               
│ line 20716: all points y value undefined!                                                                       
└ @ Gnuplot C:\Users\ms\.julia\packages\Gnuplot\jJ4hs\src\Gnuplot.jl:908                                                   
ERROR: Gnuplot error: ["all points y value undefined!"]                                                                    
Stacktrace:                                                                                                                
 [1] error(s::String)                                                                                                      
   @ Base .\error.jl:33                                                                                                    
 [2] gpexec(gp::Gnuplot.GPSession, command::String)                                                                        
   @ Gnuplot C:\Users\ms\.julia\packages\Gnuplot\jJ4hs\src\Gnuplot.jl:911                                                  
 [3] execall(gp::Gnuplot.GPSession; term::String, output::String)                                                          
   @ Gnuplot C:\Users\ms\.julia\packages\Gnuplot\jJ4hs\src\Gnuplot.jl:940                                                  
 [4] execall                                                                                                               
   @ C:\Users\ms\.julia\packages\Gnuplot\jJ4hs\src\Gnuplot.jl:921 [inlined]                                                
 [5] driver(::Symbol, ::Vararg{Any, N} where N; is3d::Bool)                                                                
   @ Gnuplot C:\Users\ms\.julia\packages\Gnuplot\jJ4hs\src\Gnuplot.jl:1336                                                 
 [6] driver(::Symbol, ::Vararg{Any, N} where N)                                                                            
   @ Gnuplot C:\Users\ms\.julia\packages\Gnuplot\jJ4hs\src\Gnuplot.jl:1262                                                 
 [7] top-level scope                                                                                                       
   @ REPL[242]:1  

```

---

<div class="post-metadata">

**Author:** ![lazarusA](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lazarusa/32/6571_2.png) [@lazarusA](https://discourse.julialang.org/u/lazarusA)\
**Post date:** [July 25, 2021, 10:27pm UTC](https://discourse.julialang.org/t/gnuplot-jl-datetime-in-xtics/65281/2 "2021-07-25T22:27:14Z")

</div>

this example might help you.

```julia
using Gnuplot, TimeSeries, MarketData, Dates
# dummy data
dates = Date(2018, 1, 1):Day(1):Date(2019, 12, 31)
ta = TimeArray(dates, rand(length(dates)))

timefmt = "%Y-%m-%d" # hour:minute:seconds are also available
pfmt = "%Y-%m-%d"
rot_xtics = -35

vals = 0.5*values(ta)
tempo = string.(timestamp(ta))

xmin1 = "2018-02-01"
xmax1 = "2019-04-01"

@gp "set xdata time" "set timefmt '\"$(timefmt)\"'" "set grid" :-
@gp :- "set format x '$(pfmt)'" "set xtics rotate by $(rot_xtics)" :-
@gp :- "set tmargin at screen 0.96; set bmargin at screen 0.15" :-
@gp :- "set lmargin at screen 0.1; set rmargin at screen 0.96" :-
@gp :- """set xrange [\'"$(xmin1)\"':\'"$(xmax1)\"']""" yrange = (-0.25,0.75) :-

@gp :- tempo vals "u 1:2 w l lc 'black' t 'series'"

```

 ![datesnobreak](https://global.discourse-cdn.com/julialang/original/3X/a/0/a039962a93ba77d864fa3209cda46236a2cab223.png)

A comple set of examples doing dates can be found here

> **[Plotting Market Data from AlphaVantage.jl with Gnuplot.jl](https://nextjournal.com/lazarus/plotting-market-data-from-alphavantagejl-with-gnuplotjl)**

the main file with all predefined functions is here  
[https://cdn.nextjournal.com/data/Qmdk7ZYTeibg3XnaDWHXG4hamxYPoqwt2MuDEjwFkdsz4R?filename=plotMarketData.jl&content-type=](https://cdn.nextjournal.com/data/Qmdk7ZYTeibg3XnaDWHXG4hamxYPoqwt2MuDEjwFkdsz4R?filename=plotMarketData.jl&content-type=)

but probably the first example will be enough.

---

<div class="post-metadata">

**Author:** ![Inna](https://avatars.discourse-cdn.com/v4/letter/i/8e8cbc/32.png) [@Inna](https://discourse.julialang.org/u/Inna)\
**Post date:** [August 5, 2021, 2:35pm UTC](https://discourse.julialang.org/t/gnuplot-jl-datetime-in-xtics/65281/3 "2021-08-05T14:35:57Z")

</div>

Dear @lazarusA ,  
Thank you very much !! Excellent examples in this link too!
