1

could someone please help me. I'm trying to create a simple chart.

set datafile separator ","
set xdata time   
set timefmt "%d/%m/%Y %H:%M:%S" 
set format x "%H:%M" 
set autoscale y
plot ["13:00":"14:00"] './data.csv' using 1:2 with lines

data.csv:

26/10/2010 13:30:01,1

26/10/2010 13:30:12,2

26/10/2010 13:30:23,3

26/10/2010 13:30:34,4

gives me the error:

line 6: all points y value undefined!

I've tried all manners of timefmt settings!

Many thanks

2 Answers 2

7

The problem is defining the xrange, it needs to be the same format timefmt (see ?time_axis)

The following works for me

set datafile separator "," 
set xdata time
set timefmt "%d/%m/%Y %H:%M:%S" 
set format x "%H:%M" 
set autoscale y 
set xrange["26/10/2010 13:00:00":"26/10/2010 14:00:00"]
plot './data.csv' using 1:2 with lines

Oh, and I got rid of the blank lines in between each line of data.

If you don't want to edit the file to get rid of the blank data, then you can use awk in gnuplot like so,

plot "<awk '$0!~/^$/ {print $0}' ./data.csv" using 1:2 with lines

for the final command.

EDIT: further info in case there is still a problem (see the comments)

I needed to use the awk command to get the data to plot. This was to remove the blank lines in the data. Combining awk and gnuplot in this fashion works on linux systems, I'm not certain about gnuplot on windows. It could be that certain piping isn't happening, in which case you would have to remove the blank lines before using gnuplot. (you could still use awk for this, but perhaps not in the plot command?)

If you are using linux and the above is not working, then something else is the problem. Perhaps there are old commands stored in the gnuplot session? To make sure we are doing exactly the same thing, I give the shell script that I used (I changed the xrange to fit the data better and make a nicer plot, also notive the \$ instead of $, otherwise the shell misinterprets the $ sign).

Okay: I made the file data.csv.sh in a new folder (in case you have data.csv or data.csv.png files already),:

#!/bin/bash

echo "26/10/2010 13:30:01,1

26/10/2010 13:30:12,2

26/10/2010 13:30:23,3

26/10/2010 13:30:34,4" > "data.csv"


gnuplot<<EOF
set term png small
set output "data.csv.png"
set datafile separator "," 
set xdata time
set timefmt "%d/%m/%Y %H:%M:%S" 
set format x "%H:%M" 
set autoscale y 
set xrange["26/10/2010 13:30:00":"26/10/2010 13:31:00"]
plot "<awk '\$0!~/^\$/ {print \$0}' ./data.csv" using 1:2 with lines
set output
set term pop
EOF 

Then on the terminal I typed:

chmod +wrx data.csv.sh && ./data.csv.sh

to make the shell script executable and then to run it.

The file data.csv.png looks like the following alt text

All the best

Tom

Sign up to request clarification or add additional context in comments.

2 Comments

Many thanks for your help Tom. Now I get a chart with a nice x & y axis, but without any data points plotted. I've played around with the data & "using" clause to no effect!
@Tony That is strange, did you use the plot "<awk ..." command? I get no data points plotted when I had the blank lines in the data file, but removing the blank lines fixed this... Sorry, forgot to ask, are you using windows or linux? If windows the awk command might not be working?
1

I just wanted to add to the above discussion in case someone was having the same issues. I was trying to plot a time series, such as:

07/22/13 01:00 120

When I tried to plot using the above procedure I got the bad time format error. I changed my input data to:

07/22/2013 01:00 120

After the change, it ran perfectly. This would make sense because to gnuplot the 07/22/13 is vague. That is, is it 1913, 1813, or 2013 (or any other yy13).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.