gnuplot:数据 table 类型值 = 'u' 和直方图中的奇怪条

gnuplot : data table type value = 'u' and strange bars in histogram boxes

我之前问过 问题。这是一个相关问题。

使用 test.txt 文件:

-0.1  0  0  JANE
1  1  1  BILL
2  2  1  BILL
1  3  1  BILL
6  4  0  JANE
35 5  0  JANE
9  6  1  BILL
4  7  1  BILL
24 8  1  BILL
28 9  1  BILL
9  10  0  JANE
16 11  1  BILL
4  12  0  JANE
45 13  1  BILL

和 Gnuplot 脚本:

file='test.txt'
binwidth=10
bin(x,width)=width*floor(x/width)

set table "data_table"

plot file using (bin(,binwidth)):(1.0) smooth freq,\
file using (1+(bin(,binwidth))):(1.0) smooth freq

unset table

set boxwidth 1
set logscale y
set yrange[0.01:15]

plot "data_table" index 0 using ():( == 0 ? 1/0 : ) with boxes,\
"data_table" index 1 using ():( == 0 ? 1/0 : ) with boxes

我得到 data_table :

# Curve 0 of 2, 7 points
# Curve title: "file using (bin(,binwidth)):(1.0)"
# x y type
-10  1  i
 0  8  i
 10  1  i
 20  2  i
 30  1  i
 40  1  i
 0  1  u


# Curve 1 of 2, 3 points
# Curve title: "file using (1+(bin(,binwidth))):(1.0)"
# x y type
 1  10  i
 11  4  i
 1  1  u

根据 Gnuplot shell 中的 "help set table" : “......字符 R 取三个值之一: "i" 如果该点在活动范围内,"o" 如果它超出范围,或者 "u" 如果未定义。"

问题1:为什么data_table中每个索引组的最后一行的值为u,为什么是x 值好像有问题?

问题 2 : 生成的图看起来与 非常相似。如果您查看 (x=0, y=1) 处的 bin,您会注意到直方图框中间有一个条。它是什么以及如何摆脱它?

  1. u 标记为未定义的多余点是由于错误,请参阅 bug #1274

  2. Gnuplot 本身不会自动遵守第三列中的值。因此,尽管每个块中的最后一个点都被标记为未定义,但 gnuplot 绘制它们会导致在 y=1 处出现额外的条。

    要摆脱它们,您必须通过检查 strcol(3) eq "u":

  3. 明确跳过第三列中具有 u 的那些点
file='test.txt'
binwidth=10
bin(x,width)=width*floor(x/width)

set table "data_table"

plot file using (bin(,binwidth)):(1.0) smooth freq,\
file using (1+(bin(,binwidth))):(1.0) smooth freq

unset table

set boxwidth 1
set logscale y
set yrange[0.01:15]
unset key

plot "data_table" index 0 using ():( == 0 || strcol(3) eq "u" ? 1/0 : ) with boxes,\
"data_table" index 1 using ():( == 0 || strcol(3) eq "u" ? 1/0 : ) with boxes