嵌套的 do 和 if 语句错过情节
nested do and if statements miss plots
我正在使用
G N U P L O T
Version 4.6 patchlevel 4 last modified 2013-10-02
Build System: Linux x86_64
我想用它来绘制大致这样设置的文件中的数据
0.0 a1 b1
0.0 a2 b2
...
0.1 a1 b1*
0.1 a2 b2*
...
对于第一列中的每个唯一值,我想在 a 上绘制 b。为此,我创建了一个包含条件绘图的 do 循环
do for [t=0:34] {
print 0.2000*t
plot 'twopi5101/profile.dat' u (==0.2000*t ? (-7.5) : 1/0):8 notitle w l lt 1 lc 1, \
'twopi5101/profile.dat' u (==0.2000*t ? (-7.5) : 1/0):9 notitle w l lt 1 lc 2
}
不幸的是,这个循环(以及其他文件的类似循环)将始终错过一些情节
0.0
0.2
0.4
0.6
warning: Skipping data file with no valid points
warning: Skipping data file with no valid points
more> ;print 0.2000*t;plot 'twopi5101/profile.dat' u (==0.2000*t ? (-7.5) : 1/0):8 notitle w l lt 1 lc 1, 'twopi5101/profile.dat' u (==0.2000*t ? (-7.5) : 1/0):9 notitle w l lt 1 lc 2;
^
x range is invalid
但是,如果我手动输入0.6就完全没有问题
gnuplot> plot 'twopi5101/profile.dat' u (==0.6 ? (-7.5) : 1/0):8 notitle w l lt 1 lc 1, \
'twopi5101/profile.dat' u (==0.6 ? (-7.5) : 1/0):9 notitle w l lt 1 lc 2
gnuplot>
对于为什么会发生这种情况,似乎没有合乎逻辑的解释,甚至连失分的规律也没有。
跳过区间 [0.0:6.0] gnuplot:
0.6,1.2,1.4,2.4,2.8,3.4,3.8,4.6,4.8,5.6,5.8
并且每次我 运行 循环时它都会这样做,即使我 运行 它只是在该间隔的一部分(例如 运行 从 0.6 到 2.0 将再次技能 0.6,1.2 和1.4).
我已经 运行 在许多其他情况下对更大的 intervals/more 图进行相同的行为。我不知道什么会导致这样的事情,或者如果我的循环格式有一些错误来解释它。
(我使用的终端是 'wxt' 或 postscript enhanced)
那是因为在相等性上测试浮点值通常不是一个好主意。让我们考虑例如:
gnuplot> print 0.6==0.6
1
gnuplot> print 0.6==3*0.2
0
这是因为像 0.2
这样的数字没有准确表示。
我建议首先将数据中的第一列转换为整数值,例如,
floor(( + 0.05)*10)
此处假定所讨论的列仅包含 0.1
的倍数。存在因子 0.05
以确保可能的不准确输入(例如 0.1000001
或 0.0999999
转换为 1
.
此转换后的值可用于 plot
命令中的过滤,例如,
plot 'twopi5101/profile.dat' u (floor((+0.05)*10)==2*t?(-7.5):1/0):8
或者,可以将条件 ==0.2000*t
替换为 abs( - 0.2000*t)<5E-2
我正在使用
G N U P L O T
Version 4.6 patchlevel 4 last modified 2013-10-02
Build System: Linux x86_64
我想用它来绘制大致这样设置的文件中的数据
0.0 a1 b1
0.0 a2 b2
...
0.1 a1 b1*
0.1 a2 b2*
...
对于第一列中的每个唯一值,我想在 a 上绘制 b。为此,我创建了一个包含条件绘图的 do 循环
do for [t=0:34] {
print 0.2000*t
plot 'twopi5101/profile.dat' u (==0.2000*t ? (-7.5) : 1/0):8 notitle w l lt 1 lc 1, \
'twopi5101/profile.dat' u (==0.2000*t ? (-7.5) : 1/0):9 notitle w l lt 1 lc 2
}
不幸的是,这个循环(以及其他文件的类似循环)将始终错过一些情节
0.0
0.2
0.4
0.6
warning: Skipping data file with no valid points
warning: Skipping data file with no valid points
more> ;print 0.2000*t;plot 'twopi5101/profile.dat' u (==0.2000*t ? (-7.5) : 1/0):8 notitle w l lt 1 lc 1, 'twopi5101/profile.dat' u (==0.2000*t ? (-7.5) : 1/0):9 notitle w l lt 1 lc 2;
^
x range is invalid
但是,如果我手动输入0.6就完全没有问题
gnuplot> plot 'twopi5101/profile.dat' u (==0.6 ? (-7.5) : 1/0):8 notitle w l lt 1 lc 1, \ 'twopi5101/profile.dat' u (==0.6 ? (-7.5) : 1/0):9 notitle w l lt 1 lc 2
gnuplot>
对于为什么会发生这种情况,似乎没有合乎逻辑的解释,甚至连失分的规律也没有。
跳过区间 [0.0:6.0] gnuplot:
0.6,1.2,1.4,2.4,2.8,3.4,3.8,4.6,4.8,5.6,5.8
并且每次我 运行 循环时它都会这样做,即使我 运行 它只是在该间隔的一部分(例如 运行 从 0.6 到 2.0 将再次技能 0.6,1.2 和1.4).
我已经 运行 在许多其他情况下对更大的 intervals/more 图进行相同的行为。我不知道什么会导致这样的事情,或者如果我的循环格式有一些错误来解释它。
(我使用的终端是 'wxt' 或 postscript enhanced)
那是因为在相等性上测试浮点值通常不是一个好主意。让我们考虑例如:
gnuplot> print 0.6==0.6
1
gnuplot> print 0.6==3*0.2
0
这是因为像 0.2
这样的数字没有准确表示。
我建议首先将数据中的第一列转换为整数值,例如,
floor(( + 0.05)*10)
此处假定所讨论的列仅包含 0.1
的倍数。存在因子 0.05
以确保可能的不准确输入(例如 0.1000001
或 0.0999999
转换为 1
.
此转换后的值可用于 plot
命令中的过滤,例如,
plot 'twopi5101/profile.dat' u (floor((+0.05)*10)==2*t?(-7.5):1/0):8
或者,可以将条件 ==0.2000*t
替换为 abs( - 0.2000*t)<5E-2