7

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

Community
  • 1
  • 1
user3863950
  • 75
  • 1
  • 1
  • 5
  • You must specify a time format for parsing your data file: `set timefmt '%d/%m/%Y %H:%M:%S'`. – Christoph Aug 01 '14 at 09:03
  • Thanks, I've tried adding that in and now its giving me an unreadable file no data in plot error – user3863950 Aug 01 '14 at 09:34
  • I know the files can be plotted as they work in a simple graph – user3863950 Aug 01 '14 at 09:35
  • 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 Aug 01 '14 at 14:51
  • 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 Aug 01 '14 at 15:24
  • Then please update your question accordingly so that you have a *minimal* script which still shows the error (remove all the key stuff, tics etc.) and tell us which gnuplot version you use. – Christoph Aug 01 '14 at 15:29
  • Done the update, and I'm on 4.6.5 – user3863950 Aug 04 '14 at 07:48
  • Ok. I do also get this error when the data file has in its first line the part `Date Time Value`. If I remove that line (or comment it out with a `#`), it works fine with 4.6.5. – Christoph Aug 04 '14 at 07:56
  • Ok I see whats going on now, I used the sample of data I gave in this question rather than my real data and it works perfectly, but if I use my real data where the date changes then I get my error message, bad sampling from my end there – user3863950 Aug 04 '14 at 10:37
  • FIXED, following that line of investigation turns out my data logger puts headings every thousand lines or so I didn't see before, delete them and I get no more error thanks Christoph! – user3863950 Aug 04 '14 at 11:01
  • I added an answer, so we can close this question. Nice, that you got it fixed :) – Christoph Aug 04 '14 at 19:14

3 Answers3

6

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
Christoph
  • 47,569
  • 8
  • 87
  • 187
  • how to give the column number dynamically e.g. in your case how can i put column 1 and 3 in a variable for `1:3 `. Please check my question on this here http://stackoverflow.com/questions/32811596/gnuplot-how-to-give-column-number-to-plot-dynamically – mtk Sep 27 '15 at 18:52
0

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'`
    
Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
Alejandro Galera
  • 3,445
  • 3
  • 24
  • 42
  • Well, the second option isn't really an option because the OP has a separate title to show. And the first option is already what my answer says... So what's your point? – Christoph Oct 17 '14 at 09:17
  • The headers weren't the problem, the problem was the footer left by the data logger I was using (100000 points down hence why i didnt see it), once i deleted the bit at the bottom, it worked fine – user3863950 Oct 20 '14 at 08:20
  • Christoph, my point is use "title columnhead" with your code or use an input file without titles with your gnuplot script. Maybe you could have choosen columnhead to avoid unreadable file error – Alejandro Galera Dec 18 '14 at 16:20
0

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.

Bernard
  • 163
  • 1
  • 1
  • 6