绘制事件,X轴为日期,Y轴为时间

时间:2019-10-31 01:59:05

标签: gnuplot

您可以为X设置timefmt的一种方式,为Y设置另一种方式吗?我的数据如下:

2019-05-08 00:14:29.000
2019-05-08 00:14:27.000
2019-05-07 22:08:09.000
2019-05-07 22:08:08.000

我的代码如下:

## X axis
set xdata time
set timefmt "%Y-%m-%d"
set format x "%m:%d"
set xrange ["2019-01-01":"2019-10-30"]
set xlabel "Date (mm:dd)" font "Times, 12"

# Y axis
set ydata time
set timefmt "%H:%M:%S"
set format y "%H:%M"
set yrange ["00:00":"23:59"]
set ylabel "Time Of Day(hh:mm)" font "Times, 12"

plot "file.data" using 1:2 with points

我看到轴看起来正确,但是没有数据。如果我删除第二个“ set timefmt”,它将抱怨没有Y数据。

我没有看到使用gnuplot的示例。有什么建议么?我有数百个数据点和50多个数据文件。

2 个答案:

答案 0 :(得分:1)

我也经常对数据/时间格式感到困惑和困惑。我的怀疑是,如果您有两个时间轴,则首先指定输入格式set timefmt "%Y-%m-%d",然后指定set timefmt "%H:%M:%S"。这不是专门用于轴的。因此,在绘制时,gnuplot采用当前(后者)格式,这对于第1列中的日期当然是错误的。但是我可能对此解释有误。

无论如何,如果您在绘图命令(timecolumn(1,"%Y-%m-%d"))中指定了格式,那应该没问题。

代码:

### two date/time axes
reset session

$Data <<EOD
2019-01-08 10:14:29.000
2019-05-08 00:14:27.000
2019-05-07 14:08:09.000
2019-05-07 22:08:08.000
2019-10-07 12:08:08.000
EOD

## X axis
set xdata time
set timefmt "%Y-%m-%d"
set format x "%m/%d"
set xrange ["2019-01-01":"2019-10-30"]
set xlabel "Date (mm/dd)" font "Times, 12"

# Y axis
set ydata time
set timefmt "%H:%M:%S"
set format y "%H:%M"
set yrange ["00:00":"23:59"]
set ylabel "Time Of Day(hh:mm)" font "Times, 12"

plot $Data using (timecolumn(1,"%Y-%m-%d")):2 w p pt 7

### end of code

结果:

enter image description here

答案 1 :(得分:1)

最好完全不使用timefmtset *data time来执行此操作,尽管这样会使设置和显式xrange更加麻烦。

$TIMES << EOT
2019-01-08 00:14:29.000
2019-05-08 03:14:27.000
2019-05-07 22:08:09.000
2019-08-07 22:08:08.000
EOT

set xtics time format "%m/%d"
set ytics time format "%H:%M"
set xlabel "Date (mm/dd)" font "Times, 12"
set ylabel "Time Of Day(hh:mm)" font "Times, 12"
set key tmargin reverse Left

set xrange [strptime("%Y-%m-%d","2019-01-01"):strptime("%Y-%m-%d","2019-10-30")]

plot $TIMES using (timecolumn(1,"%Y-%m-%d")) : (timecolumn(2,"%H:%M:%S")) with points

enter image description here

相关问题