问题是定义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 如下所示
一切顺利
汤姆