2

我想知道是否有一种方法可以在 gnuplot 中绘制重复的点而不让它们不可见,将点置于 (X+rand(-0.5;0.5),Y+rand(-0.5;0.5))。所以点不是放在前一点的 X/Y 上,而是 - 取决于随机化 - 稍微向上、向下、向左或向右。然后没有点变得不可见。

这种效应称为“抖动”。这是一个很好的例子: http: //www.ats.ucla.edu/stat/spss/faq/jitter.htm

4

1 回答 1

4

要将随机偏差添加到数据点,只需使用以下rand函数:

myrand(x) = (x + rand(0) - 0.5)
plot 'data.dat' using (myrand($1)):(myrand($2))

rand(0)生成范围内的值[0:1]

如果要多次绘制每个点,则需要多次迭代:

plot for [i=0:4] 'data.dat' using (myrand($1)):(myrand($2))

为了考虑出现次数,如您的链接中所示,必须花点功夫。

考虑数据文件(取自http://www.ats.ucla.edu/stat/spss/faq/jitter.htm),第三列包含出现次数:

1 1 4
1 2 7
1 3 6
2 1 9
2 2 5
2 3 11
3 1 1
3 2 2
3 3 3
4 1 12
4 2 8
4 3 10

一种方法是从数据文件中提取最大出现次数,然后用迭代绘制。在每次迭代中,如果其出现​​次数高于当前迭代索引,则添加一个点。通过将一个坐标设置为 来跳过一个点1/0

stats 'data.dat' using 3 nooutput
set style line 1 pointtype 6 linecolor -1
myrand(x) = x + 0.3 * (rand(0) - 0.5)
plot for [i=0:int(STATS_max)-1] 'data.dat' \
    using (myrand($1)):(i < $3 ? myrand($2) : 1/0) linestyle 1 notitle

这给出了(4.6.3):

在此处输入图像描述

我在哪里使用了附加设置:

set terminal pngcairo
set output 'data.png'
set xtics 1
set ytics 1
set autoscale fix
set offset 0.5,0.5,0.5,0.5
于 2013-10-16T08:03:13.353 回答