gnuplot - 读取双引号日期时间戳

发布于 2025-01-09 15:14:23 字数 718 浏览 0 评论 0原文

我正在尝试学习 gnuplot,我想绘制一些逗号分隔的数据。

  • x 轴日期时间戳 - 用双引号括起来 - 包含逗号分隔符,
  • y 轴整数值数据。
"1/31/22, 4:36",0
"1/31/22, 16:30",1
"1/31/22, 16:39",2
"2/1/22, 16:44",3
"2/1/22, 9:25",4
"2/7/22, 13:59",5
"2/7/22, 8:57",6
"2/8/22, 11:03",7
"2/18/22, 15:50",8
"2/21/22, 11:11",9
"2/24/22, 9:11",10

如何读取这些数据并在 gnuplot 中绘图?
我尝试了以下操作,但收到有关“警告:跳过没有有效点的数据文件”的错误,

set xdata time
set timefmt "\"%m/%d/%Y, %H:%M\""
set format x “%d/%m/%Y”
set datafile separator ","
plot "file.txt" using 1:2 with linespoints

我认为我的 timefmt 不正确。正确的语法是什么?

gnuplot 还可以使用 AM/PM 处理以下格式的日期时间戳吗?

"1/31/22, 4:36 AM",0
"1/31/22, 4:30 PM",1

I am trying learn gnuplot and I want to to plot some comma separated data.

  • x axis datetime stamp - enclosed in double quotes - containing a comma separator,
  • y axis integer value data.
"1/31/22, 4:36",0
"1/31/22, 16:30",1
"1/31/22, 16:39",2
"2/1/22, 16:44",3
"2/1/22, 9:25",4
"2/7/22, 13:59",5
"2/7/22, 8:57",6
"2/8/22, 11:03",7
"2/18/22, 15:50",8
"2/21/22, 11:11",9
"2/24/22, 9:11",10

How do I read this data and plot in gnuplot?
I tried the following but get error about "warning: Skipping data file with no valid points"

set xdata time
set timefmt "\"%m/%d/%Y, %H:%M\""
set format x “%d/%m/%Y”
set datafile separator ","
plot "file.txt" using 1:2 with linespoints

I assume my timefmt is incorrect. What is the correct syntax?

Also can gnuplot process datetime stamps in the following format with AM/PM?

"1/31/22, 4:36 AM",0
"1/31/22, 4:30 PM",1

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

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

发布评论

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

评论(1

痴梦一场 2025-01-16 15:14:23

检查帮助时间说明符。您的年份是 2 位数字 %y,而不是 4 位数字 %Y
双引号将使您的日期/时间成为第一列。格式中不需要额外的双引号。

使用语法 set xdata timeset timefmt "..." 在绘图命令中只有一种格式。
如果您使用语法 timecolumn()(请查看 help timecolumn),您可以在绘图命令中使用不同的输入时间格式。

注意:格式 %p 作为输入格式已在 gnuplot 5.4.0 中引入
对于旧版本,您必须使用解决方法,请参阅 gnuplot:如何将 12 小时时间格式转换为 24 小时时间格式?

<强>代码:

### plot timedata in double quotes and AM/PM format
reset session

$Data1 <<EOD
"1/31/22, 4:36",0
"1/31/22, 16:30",1
"1/31/22, 16:39",2
"2/1/22, 16:44",3
"2/1/22, 9:25",4
"2/7/22, 13:59",5
"2/7/22, 8:57",6
"2/8/22, 11:03",7
"2/18/22, 15:50",8
"2/21/22, 11:11",9
"2/24/22, 9:11",10
EOD

$Data2 <<EOD
"1/31/22, 4:36 AM",0
"1/31/22, 4:30 PM",1
"1/31/22, 4:39 PM",2
"2/1/22,  4:44 PM",3
"2/1/22, 9:25 AM",4
"2/7/22, 1:59 PM",5
"2/7/22, 8:57 AM",6
"2/8/22, 11:03 AM",7
"2/18/22, 3:50 PM",8
"2/21/22, 11:11 AM",9
"2/24/22, 9:11 AM",10
EOD

set datafile separator comma

myTimeFmt1 = "%m/%d/%y, %H:%M"
myTimeFmt2 = "%m/%d/%y, %H:%M %p"
set format x "%d/%m/%Y" time

plot $Data1 u (timecolumn(1,myTimeFmt1)):2 w lp pt 7 ps 2 lc "grey" lw 4 ti "Data1", \
     $Data2 u (timecolumn(1,myTimeFmt2)):2 w lp pt 7 ps 1 lc "red"  lw 1 ti "Data2"
### end of code

结果:

在此处输入图像描述

Check help time_specifiers. Your year it 2 digits %y not 4 digits %Y.
The double quotes will make your date/time the first column. No need for extra double quotes in the format.

With the syntax set xdata time and set timefmt "..." you have only one format in the plot command.
If you are using the syntax timecolumn() (check help timecolumn) you can use different input time formats in your plot command.

Note: the format %p as input format has been introduced in gnuplot 5.4.0
For older versions you have to use a workaround, see e.g. gnuplot: how to convert 12h time format into 24h time format?

Code:

### plot timedata in double quotes and AM/PM format
reset session

$Data1 <<EOD
"1/31/22, 4:36",0
"1/31/22, 16:30",1
"1/31/22, 16:39",2
"2/1/22, 16:44",3
"2/1/22, 9:25",4
"2/7/22, 13:59",5
"2/7/22, 8:57",6
"2/8/22, 11:03",7
"2/18/22, 15:50",8
"2/21/22, 11:11",9
"2/24/22, 9:11",10
EOD

$Data2 <<EOD
"1/31/22, 4:36 AM",0
"1/31/22, 4:30 PM",1
"1/31/22, 4:39 PM",2
"2/1/22,  4:44 PM",3
"2/1/22, 9:25 AM",4
"2/7/22, 1:59 PM",5
"2/7/22, 8:57 AM",6
"2/8/22, 11:03 AM",7
"2/18/22, 3:50 PM",8
"2/21/22, 11:11 AM",9
"2/24/22, 9:11 AM",10
EOD

set datafile separator comma

myTimeFmt1 = "%m/%d/%y, %H:%M"
myTimeFmt2 = "%m/%d/%y, %H:%M %p"
set format x "%d/%m/%Y" time

plot $Data1 u (timecolumn(1,myTimeFmt1)):2 w lp pt 7 ps 2 lc "grey" lw 4 ti "Data1", \
     $Data2 u (timecolumn(1,myTimeFmt2)):2 w lp pt 7 ps 1 lc "red"  lw 1 ti "Data2"
### end of code

Result:

enter image description here

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