问题
I'm trying to generate a graph with gnuplot but it seems that it doesn't show the correct values: Data are:
03/18/2014 15:00:50 32,4
03/18/2014 14:00:48 32,4
03/18/2014 13:00:48 32,42
03/18/2014 12:00:44 32,4
03/18/2014 11:00:42 122,2
03/18/2014 10:00:47 22,4
03/18/2014 09:00:37 53,9
03/18/2014 08:00:35 14,2
The sh is:
#!/usr/bin/gnuplot
set title "Plot x^2"
set terminal png
set output "output.png"
set xlabel "X"
set ylabel "Y"
#set datafile sep ','
set xdata time
set timefmt '%m/%d/%Y %H:%M:%S'
plot 'pepe.csv' using 1:2 with lines
It shows me:
回答1:
@andyras' suggestion of set decimalsign ',' is helpful but if you have a space in the time format then it counts as more than one column. Quoting the documentation:
Each set of non-blank characters in the timedata counts as one column in the using n:n specification. Thus 11:11 25/12/76 21.0 consists of three columns. To avoid confusion, gnuplot requires that you provide a complete using specification if your file contains timedata.
This means that you need to change using 1:2 to using 1:3.
Using your original data, this script works for me:
#!/usr/bin/gnuplot
set title "Plot x^2"
set terminal png
set output "output.png"
set xlabel "X"
set ylabel "Y"
set decimalsign ','
set timefmt '%m/%d/%Y %H:%M:%S'
set xdata time
plot 'decimal.txt' u 1:3 with lines
Output:
Alternatively, you could use a different data separator in your datafile, such as a , and the time will only count as one column. To do this you add the line set datafile sep ',' to your script.
edit: you might want to also consider using the pngcairo terminal (set term pngcairo), as it looks a lot better:
来源:https://stackoverflow.com/questions/22483163/incorrect-values-when-plotting-from-file-containing-time-data-gnuplot