Incorrect values when plotting from file containing time data - gnuplot

夙愿已清 提交于 2019-12-24 06:37:26

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!