Search code examples
gnuplot

GNUPLOT incorrect date behavior


GNU plot is giving a strange behavior with this data, but I cannot figure our why.

here is my data example :

-2.696764488716512156e-02 2023-05-25
-2.514640039066843094e-02 2023-05-25
-2.539875589417509363e-02 2023-05-25
-2.443511139767776813e-02 2023-05-25
-2.258826690118204833e-02 2023-05-25
-2.176542240468394215e-02 2023-05-25

Now using HOURS time work, but I am trying to plot for DAYS with this configuration :

set terminal png size 1074,806
set output 'output.png'
set datafile sep ' '
set xdata time
set timefmt "%Y-%m-d%"
set format x "%m/%d"
set autoscale y
set style data lines
set xlabel 'Days'
plot "gnudataok.dat"  using 2:1 with lines lt rgb "blue"  

But I cannot get correct dates on the X axis

enter image description here


Solution

  • There is a typo in your script "%Y-%m-d%" instead of "%Y-%m-%d"

    Note, if your time precision is just whole days, all these datapoints will be plotted on top of each other.

    The following script (with some dates changed) will give the result below...

    Script:

    ### time data
    reset session
    
    $Data <<EOD
    -2.696764488716512156e-02 2023-05-25
    -2.514640039066843094e-02 2023-05-25
    -2.539875589417509363e-02 2023-05-26
    -2.443511139767776813e-02 2023-05-26
    -2.258826690118204833e-02 2023-05-27
    -2.176542240468394215e-02 2023-05-27
    EOD
    
    myTimeFmt = "%Y-%m-%d"
    set format x "%m/%d" timedate
    set xlabel 'Days'
    
    plot $Data u (timecolumn(2,myTimeFmt)):1 w lines lc rgb "blue"
    ### end of script
    

    Result:

    enter image description here