Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
588 views
in Technique[技术] by (71.8m points)

gnuplot v4.4: Problem plotting using timeseries x axis

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...