【问题标题】:Why is there a discrepancy between the regular x-axis and the x2-axis in gnuplot time data plots?为什么 gnuplot 时间数据图中的常规 x 轴和 x2 轴之间存在差异?
【发布时间】:2018-02-18 03:28:33
【问题描述】:

所以我注意到了一些我无法解释的事情。如果我在 gnuplot 中的 x 轴和 x2 轴上都有时间值,则相同的数据点不会对齐。让我用一个最小的工作示例来详细说明。

我有两个数据文件:

一个有实际数据的:

# time1.dat - Some data:
1516205221  1
1516295221  2   "lbl1"
1516626421  3   "lbl2"
1518193566  4   "lbl3"
1518433621  5   "lbl4"
1518539166  6
1518599166  7

还有一个带有一些数据点标签的标签:

# Some labels
1516295221  "label1"
1516626421  "label2"
1518193566  "label3"
1518433621  "label4"

每个文件中的第一列是以 unix 纪元格式表示的时间(即自 1970 年 1 月 1 日 00:00:00 以来的秒数)。请注意,两个文件中的某些行如何具有相同的纪元,例如线

1516295221  2   "lbl1"

time1.dat 中与time2.dat 中标记为"label 1" 的行具有相同的纪元。

现在如果我运行

reset
set xdata time
set x2data time
set timefmt "%s" # epoch
set x2tics

set tics nomirror front; set yrange [0:]

plot \
    'time1.dat' using ($1):($2):($3) with labels offset 0, char 1 notitle, \
    'time1.dat' using ($1):($2) with points notitle, \
    'time2.dat' using ($1):(NaN):x2tic(2) notitle

我得到了下图中的不匹配。数据点“lbl1”应与 xtic“label1”(与“label2”相同)对齐。但他们没有。为什么会这样?我该如何解决这个问题?

我不确定这是错误还是预期行为,我只是缺少一个设置。

【问题讨论】:

    标签: plot gnuplot


    【解决方案1】:

    xx2 轴完全不相关。它们有自己的范围、规模和方向。使用set link 强制这些轴之间的固定关系。

    在您的情况下,只需使用set link x2x2 等同于x

    reset
    set xdata time
    set x2data time
    set timefmt "%s" # epoch
    set x2tics
    
    set tics nomirror front; set yrange [0:]
    set link x2
    plot \
        'time1.dat' using ($1):($2):($3) with labels offset 0, char 1 notitle, \
        'time1.dat' using ($1):($2) with points notitle, \
        'time2.dat' using ($1):(NaN):x2tic(2) notitle
    

    【讨论】:

      【解决方案2】:

      看来:

      set autoscale xfix
      set autoscale x2fix
      

      xx2 轴都需要对齐。

      不知道为什么,但它是一个修复。但是,它具有自动缩放带来的所有其他问题。我仍然对保留现有范围和缩放的解决方案持开放态度。

      【讨论】:

      • 您可以将set xrange[:]set x2range[:]xfixx2fix 结合使用。也可以使用stats 命令为给定文件设置动态xrange
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-07-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-31
      • 1970-01-01
      相关资源
      最近更新 更多