Gnuplot.jl: Datetime in xtics

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

 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

@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:

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

@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:

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:

@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:

┌ 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

@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 :

┌ 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  

this example might help you.

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'"

A comple set of examples doing dates can be found here

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

but probably the first example will be enough.

1 Like

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