plot - 为什么 gnuplot 时间数据图中的常规 x 轴和 x2 轴之间存在差异?

标签 plot gnuplot

所以我注意到一些我无法解释的事情。如果我在 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.dattime2.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”也是如此)。但他们没有。为什么会这样?我该如何解决这个问题?

mismatch between two gnuplot time axis

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

最佳答案

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

enter image description here

关于plot - 为什么 gnuplot 时间数据图中的常规 x 轴和 x2 轴之间存在差异?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48750091/

相关文章:

plot - 从文件中进行 Gnuplot 3D 绘图,x、y 和 z 刻度上的详细值不够

r - png 和 pdf 图的导出之间的差异

ios - 核心图 - 绘制长日期和整数

matlab - 在 MATLAB 绘图中忽略 NaN?

gnuplot - Gnuplot 可以处理 png 透明度吗?

gnuplot - 在 gnuplot 中绘制两条线

python - 如何更改 Statsmodel 分解图中折线图的颜色

r - 如何在 R 中以固定网格模式绘制 "matrix"

python - Gnuplot:第 0 行:绘制预期的函数

height - 增加 gnuplot 输出的宽度和高度