gnuplot v4.4:使用时间序列 x 轴绘制问题

发布于 2024-10-01 13:55:40 字数 489 浏览 0 评论 0原文

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

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 设置的所有方式!

非常感谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

橘和柠 2024-10-08 13:55:40

问题是定义 xrange,它需要具有相同的格式 timefmt (参见?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

哦,我去掉了每行数据之间的空白行。

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

plot "<awk '$0!~/^$/ {print $0}' ./data.csv" using 1:2 with lines

作为最终命令。

编辑:进一步信息,以防仍然存在问题(请参阅评论)

我需要使用 awk 命令来获取要绘制的数据。这是为了删除数据中的空白行。以这种方式组合 awk 和 gnuplot 适用于 Linux 系统,我不确定 Windows 上的 gnuplot。可能某些管道没有发生,在这种情况下,您必须在使用 gnuplot 之前删除空白行。 (你仍然可以使用 awk 来实现这一点,但也许不能在plot命令中使用?)

如果你使用的是linux并且上面的方法不起作用,那么问题就出在其他地方。也许 gnuplot 会话中存储了旧命令?为了确保我们做的是完全相同的事情,我给出了我使用的 shell 脚本(我更改了 xrange 以更好地适应数据并制作更好的图,还要注意 \$ 而不是 $,否则 shell 会误解 $符号)。

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

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

然后在终端上输入

chmod +wrx data.csv.sh && ./data.csv.sh

: shell脚本可执行文件,然后运行它。

文件 data.csv.png 如下所示 alt text

一切顺利

祝汤姆

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

合约呢 2024-10-08 13:55:40

我只是想补充一下上面的讨论,以防有人遇到同样的问题。我试图绘制时间序列,例如:

07/22/13 01:00 120

当我尝试使用上述过程进行绘制时,出现了错误的时间格式错误。我将输入数据更改为:

07/22/2013 01:00 120

更改后,它运行完美。这是有道理的,因为对于 gnuplot 来说 07/22/13 是模糊的。也就是说,是 1913 年、1813 年还是 2013 年(或任何其他 yy13)。

I just wanted to add to the above discussion in case someone was having the same issues. I was trying to plot a time series, such as:

07/22/13 01:00 120

When I tried to plot using the above procedure I got the bad time format error. I changed my input data to:

07/22/2013 01:00 120

After the change, it ran perfectly. This would make sense because to gnuplot the 07/22/13 is vague. That is, is it 1913, 1813, or 2013 (or any other yy13).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文