如何根据点的 class 制作 3D 密度图

How to make 3D density plot based on the class of the point

我正在尝试绘制数据点的 XYZ 图。每个数据都有一个与“1”错误或“0”成功相关联的值。我的数据在这个link。 作为第一次尝试,我使用了 splot

splot "data_all.dat" u 1:2:3:4 w points ls 1 palette title "P_{error}"

这个图的问题是不能很好地区分点之间的相对位置和它们在space中的位置。为了解决这个问题,一个先例问题 提供了一种基于点密度降低颜色的解决方案。

我想通过在标准中包含每个点(错误或成功)的 class 来为它们着色来扩展该问题。也就是说,考虑两种类型的点来进行着色,并绘制所有 classes 点。

我没有精确的着色方法,但我的想法是使用像 (1 - a) x (num_success_in_delta) + (a x num_errors_in_delta) 这样的函数,其中 a 是一个实数 [0,1],它对球中的错误和成功点 delta。在错误样本和成功样本之间插入 XYZ 点可能是另一种方法,但我不知道如何在 Gnuplot 中解决它。

为了改善点密度的信息,如果可能的话,XY 平面上的等值线投影或 2D 密度图可能会更清楚。 我希望制作一个 eps 文件以作为图形包含在 LaTeX 中,其质量可提供 Gnuplot 或 pgfplots。

此致

下面的代码是对此处解决方案 () 的轻微修改。错误和成功的发生次数都计入一定数量(2*DeltaX x 2*DeltaY x 2*DeltaZ)。 结果存储在一个文件中,因此,您只需计算一次(您的 10'000 行数据在我的旧 PC 上花费了大约 1 小时 15 分钟)。也许,可以使 gnuplot 代码更有效率。好吧,然后您使用下面的第二个代码并快速绘制生成的文件。我不确定哪种着色方式最好。您可以玩调色板。举个例子,下面的代码使用红色 (-1) 表示最大错误计数(即密度),使用绿色 (+1) 表示最大成功密度。我希望这在某种程度上有助于作为进一步优化的起点。

### 3D density plot
reset session

FILE = "data_all.dat"

DeltaX = 0.5  # half boxwidth
DeltaY = 0.5  # half boxlength
DeltaZ = 0.5  # half boxheight

TimeStart = time(0.0)

# put the datafile/dataset into arrays
stats FILE nooutput
RowCount = STATS_records
array ColX[RowCount]
array ColY[RowCount]
array ColZ[RowCount]
array ColR[RowCount]   # Result 0=Success, 1=Error
array ColCE[RowCount]  # Counts Error
array ColCS[RowCount]  # Counts Success
do for [i=1:RowCount] {
set table $Dummy
    plot FILE u (ColX[[=10=]+1]=,0):(ColY[[=10=]+1]=,0):(ColZ[[=10=]+1]=,0):(ColR[[=10=]+1]=,0) with table
unset table
}

# look at each datapoint and its sourrounding
Error = 1
Success = 0
do for [i=1:RowCount] {
    print sprintf("Datapoint %g of %g",i,RowCount)
    x0 = ColX[i]
    y0 = ColY[i]
    z0 = ColZ[i]
    # count the datapoints with distances <Delta around the datapoint of interest
    set table $ErrorOccurrences
        plot FILE u ((abs(x0-)<DeltaX) & (abs(y0-)<DeltaY) & (abs(z0-)<DeltaZ) & (==Error)? 1 : 0):(1) smooth frequency
    unset table
    set table $SuccessOccurrences
        plot FILE u ((abs(x0-)<DeltaX) & (abs(y0-)<DeltaY) & (abs(z0-)<DeltaZ) & (==Success) ? 1 : 0):(1) smooth frequency
    unset table
    # extract the number from $Occurrences which will be used to color the datapoint
    set table $ErrorDummy
        plot $ErrorOccurrences u (c0=,0):([=10=]) every ::1::1 with table
    unset table
    ColCE[i] = c0
    set table $SuccessDummy
        plot $SuccessOccurrences u (c0=,0):([=10=]) every ::1::1 with table
    unset table
    ColCS[i] = c0
}

# put the arrays into a dataset again
set print $Data
do for [i=1:RowCount] {
    print sprintf("%g\t%g\t%g\t%g\t%g\t%g",ColX[i],ColY[i],ColZ[i],ColR[i],ColCE[i],ColCS[i])
}
set print

stats $Data u 5:6 nooutput
CEmax = STATS_max_x
CSmax = STATS_max_y
print CEmax, CSmax

TimeEnd = time(0.0)
print sprintf("Duration: %.3f sec",TimeEnd-TimeStart)

set print "data_all_color.dat"
    print $Data
set print

set palette defined (-1 "red", 0 "white", 1 "green")
splot $Data u 1:2:3:(==1? -/CEmax : /CSmax) w p ps 0.5 pt 7 lc palette z notitle
### end of code

计算出现次数后,只需绘制新数据文件并使用调色板即可。

### 3D density plot
reset session

FILE = "data_all_color.dat"

stats FILE u 5:6 nooutput  # get maxium count from Error and Success
CEmax = STATS_max_x
CSmax = STATS_max_y
print CEmax, CSmax

set ztics 0.2
set view 50,70
set palette defined (-1 "red", 0 "white", 1 "green")

splot FILE u 1:2:3:(==1? -/CEmax : /CSmax) w p ps 0.2 pt 7 lc palette z notitle
### end of code

例如您的数据:

补充: </code> 和 <code> 列当前分别包含特定卷中出现错误和成功的绝对次数。如果你想要错误概率(但我不是统计学家),但我的猜测是你必须将错误 [​​=13=] 的出现次数除以本卷中的事件总数 +

splot FILE u 1:2:3:(/(+)) w p ps 0.2 pt 7 lc palette z notitle

另一个例子的调色板是 set palette rgb 33,13,10 一般来说,对于调色板,请参考 help palette,您会找到很多详细信息。