6
votes

What I want to do is plot a graph where my x axis takes a date from the first column of data and then a time from my second column and uses both to create the x axis,

I have a set of data from a date logger that I want to graph on gnuplot, as I get new data every day and it would be so easy to just add on each txt file as I get them

The text files look like this (each span 24 hours)

Date Time Value

30/07/2014 00:59:38 0.075
30/07/2014 00:58:34 0.102
30/07/2014 00:57:31 0.058
30/07/2014 00:56:31 0.089
30/07/2014 00:55:28 0.119
30/07/2014 00:54:26 0.151
30/07/2014 00:53:22 0.17
30/07/2014 00:52:19 0.171
30/07/2014 00:51:17 0.221
30/07/2014 00:50:17 0
30/07/2014 00:49:13 0
30/07/2014 00:48:11 0
30/07/2014 00:47:09 0

This solution mixing date and time on gnuplot xaxis would suit me perfectly, but its very complex and I have no idea what is going on, let alone apply it to multiple files

Here's the code I tried, but I get an illegal day of the month error?

#!/gnuplot
set timefmt '%d/%m/%Y %H:%M:%S'
set xdata time
set format x '%d/%m/%Y %H:%M:%S'



#DATA FILES
plot '30.07.2014 Soli.txt'  using 1:3 title '30/07/2014'  with points pt 5 lc rgb 'red',\
     '31.07.2014 Soli.txt'  using 1:3 title '31/07/2014'  with points pt 5 lc rgb 'blue'

All help appreciated! Thanks

3
You must specify a time format for parsing your data file: set timefmt '%d/%m/%Y %H:%M:%S'. - Christoph
Thanks, I've tried adding that in and now its giving me an unreadable file no data in plot error - user3863950
I know the files can be plotted as they work in a simple graph - user3863950
I get your 'illegal month' error if the data file contains the header line ('Date Time Value'). If you remove that you should get an 'empty xrange' warning. If you now add the set timefmt stuff it works fine for me. - Christoph
I deleted the headers and stuck your set timefmt '%d/%m/%Y %H:%M:%S' in just before my set xdata time and I still get the illegal day of the month error line 24 - user3863950

3 Answers

6
votes

Such an error is triggered, if some unexpected data appears in the data file, like an uncomment and unused header line in your case.

The following file.dat

Date Time Value
30/07/2014 00:59:38 0.075
30/07/2014 00:58:34 0.102

gives such an error with the minimal script

set xdata time
set timefmt '%d/%m/%Y %H:%M:%S'
plot 'file.dat' using 1:3

To solve the error, remove the first line (or similar lines in between).

Since version 4.6.6 you could also use the skip option to skip some lines at the beginning of the data file like:

set xdata time
set timefmt '%d/%m/%Y %H:%M:%S'
plot 'file.dat' using 1:3 skip 1
0
votes

I wanted to note that you probably don't have to remove non-compliant lines like the "Date Time Value" header line --- you can just comment it out instead with the hash/pound/octothorp:

#Date Time Value

This will then be ignored by Gnuplot at plot time, but stay visible to you when you want to remember which data is in which column.

0
votes

You get "month error" due to first line.

Your first line "Date Time Value" doesn't match with time format.

In my humble opinion, you have 2 options.

  1. Delete first line and set titles manually and don't change anything of your code

    30/07/2014 00:59:38 0.075
    30/07/2014 00:58:34 0.102
    30/07/2014 00:57:31 0.058`
    
  2. Keep without changes data file and modify titles in your gnuplot code, setting columnhead in order to ignore first line in your data file:

    plot '30.07.2014 Soli.txt'  using 1:3 title columnhead  with points pt 5 lc rgb 'red',\
      '31.07.2014 Soli.txt'  using 1:3 title columnhead  with points pt 5 lc rgb 'blue'`