从包含时间数据的文件进行绘图时值不正确-gnuplot [英] Incorrect values when plotting from file containing time data - gnuplot

查看:48
本文介绍了从包含时间数据的文件进行绘图时值不正确-gnuplot的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用gnuplot生成图形,但似乎它没有显示正确的值:数据是:

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

sh是:

#!/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

它告诉我:

推荐答案

@andyras'建议的 set decimalsign','很有帮助,但如果时间格式中有空格,则视为多于一列.引用文档:

@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:

时间数据中的每组非空白字符在使用n:n规范中均计为一列.因此11:11 25/12/76 21.0由三栏组成.为避免混淆,如果文件包含时间数据,gnuplot要求您提供完整的使用规范.

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.

这意味着您需要将使用<1:2 的更改为使用1:3 .

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

输出:

或者,您可以在数据文件中使用其他数据分隔符,例如,并且时间将仅计为一列.为此,您将 set datafile sep','行添加到脚本中.

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.

编辑:您可能还想考虑使用 pngcairo 终端( set term pngcairo ),因为它看起来要好得多:

edit: you might want to also consider using the pngcairo terminal (set term pngcairo), as it looks a lot better:

这篇关于从包含时间数据的文件进行绘图时值不正确-gnuplot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆