使用时间序列x轴进行绘图时出现问题

使用时间序列x轴进行绘图时出现问题

本文介绍了gnuplot v4.4:使用时间序列x轴进行绘图时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮助我吗?我正在尝试创建一个简单的图表.

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

给我错误:

line 6: all points y value undefined!

我尝试了各种方式的timefmt设置!

I've tried all manners of timefmt settings!

非常感谢

推荐答案

问题在于定义xrange,它的格式必须与timefmt相同(请参见?time_axis)

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

以下对我有用的

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.

如果您不想编辑文件以除去空白数据,则可以像这样在gnuplot中使用awk,

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

最后一条命令.

如果还有问题(请参阅评论)

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

我需要使用awk命令来获取要绘制的数据.这是为了删除数据中的空白行.以这种方式将awk和gnuplot结合起来可以在linux系统上使用,但我不确定Windows上的gnuplot.可能是某些管道未发生,在这种情况下,您必须在使用gnuplot之前删除空白行. (您仍然可以为此使用awk,但也许不在plot命令中?)

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?)

如果您使用的是Linux,但以上操作均不起作用,则可能是其他问题.也许在gnuplot会话中存储了旧命令?为了确保我们做的完全一样,我给了我使用的shell脚本(我更改了xrange以更好地拟合数据并绘制出更好的图,同时注意\ $而不是$,否则shell会误解$符号).

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).

好的:我在新文件夹中创建了data.csv.sh文件(如果您已经有data.csv或data.csv.png文件),

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

使Shell脚本可执行,然后运行它.

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

data.csv.png文件如下所示

The file data.csv.png looks like the following

祝一切顺利

汤姆

这篇关于gnuplot v4.4:使用时间序列x轴进行绘图时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 12:02