Gnuplot:散点图和密度

Sam*_*uel 5 gnuplot scatter-plot

我有代表星团的 x 和 y 数据点。我想使用 Gnuplot 及其带有重叠点的散点函数来可视化密度。

我使用了以下命令:

 set style fill transparent solid 0.04 noborder
 set style circle radius 0.01
 plot "data.dat" u 1:2 with circles lc rgb "red"
Run Code Online (Sandbox Code Playgroud)

结果:

在此处输入图片说明

但是我想要这样的东西

在此处输入图片说明

这在 Gnuplot 中可能吗?有任何想法吗?

the*_*ozh 6

编辑:修订和简化

可能比我之前的答案更好的方法如下:对于每个数据点,检查半径 内有多少其他数据点R。您需要研究该值或R获得一些合理的图表。

索引数据线需要 gnuplot>=5.2.0 和数据块中的数据(没有空行)。您可以首先将文件绘制到数据块中(选中help table)或参见此处: gnuplot:将数据文件 1:1 加载到数据块中

创建此图的时间将随着点数量 O(N^2) 的增加而增加,因为您必须对照所有其他点检查每个点。我不确定是否有更智能、更快的方法。下面的示例包含 1200 个数据点,在我的笔记本电脑上大约需要 4 秒。您基本上可以将相同的原理应用于3D

脚本:适用于 gnuplot>=5.2.0

### 2D density color plot
reset session

t1 = time(0.0)
# create some random rest data
set table $Data
    set samples 700
    plot '+' u (invnorm(rand(0))):(invnorm(rand(0))) w table
    set samples 500
    plot '+' u (invnorm(rand(0))+2):(invnorm(rand(0))+2) w table
unset table
print sprintf("Time data creation: %.3f s",(t0=t1,t1=time(0.0),t1-t0))

# for each datapoint: how many other datapoints are within radius R
R = 0.5     # Radius to check
Dist(x0,y0,x1,y1) = sqrt((x1-x0)**2 + (y1-y0)**2)
set print $Density
    do for [i=1:|$Data|] {
        x0 = real(word($Data[i],1))
        y0 = real(word($Data[i],2))
        c  = 0
        stats $Data u (Dist(x0,y0,$1,$2)<=R ? c=c+1 : 0) nooutput
        d = c / (pi * R**2)             # density: points per unit area
        print sprintf("%g %g %d", x0, y0, d)
    }
set print
print sprintf("Time density check: %.3f sec",(t0=t1,t1=time(0.0),t1-t0))

set size ratio -1   # same screen units for x and y
set palette rgb 33,13,10
plot $Density u 1:2:3 w p pt 7 lc palette z notitle
### end of script
Run Code Online (Sandbox Code Playgroud)

结果:

在此输入图像描述