如何绘制显示其密度的 (x,y,z) 点
How to plot (x,y,z) points showing their density
我的数据文件是一组位于轴原点周围的 (x,y,z) 点。它们代表某种措施失败的点。
这些点在这个link.
Gnuplot 可以绘制它们,
set encoding iso_8859_1
set term postscript eps enhanced color size 4.7in,4in
set xlabel "X"
set ylabel "Y"
set zlabel "Z"
set output "test_gp.eps"
set style line 1 lc rgb '#0060ad' pt 7 ps 0.5 lt 1 lw 0.5 # --- blue
set style fill transparent solid 0.15 noborder
splot "data.dat" u 1:2:3 w p ls 1 title "P_{error}"
结果图
问题是图中没有显示错误更有可能发生的地方。
如果可能的话,我想展示点密度的变化。
我不知道是否可以改变点的颜色或赋予它们透明度并尝试表示点密度最高的位置。
如果无法表示 3D 点的密度,另一种方法是在三个平面 (x=0,y,z), (x,y=0) 中制作点的投影密度,z), (x,y,z=0)。
此致
编辑:
我可以用不同的颜色绘制实验的成功 (0
) 和错误 (1
) 点位置。此 link 中的文件有第 4 列,其中包含所有数据样本(0 和 1)。
splot
图
splot "data_all.dat" u 1:2:3:4 w points ls 1 palette title "P_{error}"
是
但是这个数字没有显示点的密度。
例如,在 Mathematica 中,这些数据样本的密度图是
如何使用 Gnuplot
获得密度图?。很可能 Mathematica 正在对中间的点进行插值并赋予它们介于 0 和 1 之间的值,但我不知道如何使用 Gnuplot 实现它。
@user1993416,我想你可以用 gnuplot 做点什么。您可能需要使用参数 Delta
。用我 8 岁的电脑 1000 点大约需要。 2分钟。
以下代码:
### 3D density plot
reset session
set term wxt
N = 1000 # number of datapoints
Delta = 2 # half boxwidth
TimeStart = time(0.0)
# create dummy some dummy data
set samples N
set table $Data
plot '+' u (invnorm(rand(0))):(invnorm(rand(0))):(invnorm(rand(0))) with table
unset table
# put the datafile/dataset into arrays
stats $Data nooutput
RowCount = STATS_records
array ColX[RowCount]
array ColY[RowCount]
array ColZ[RowCount]
array ColC[RowCount]
do for [i=1:RowCount] {
set table $Dummy
plot $Data u (ColX[[=10=]+1]=,0):(ColY[[=10=]+1]=,0):(ColZ[[=10=]+1]=,0) with table
unset table
}
# look at each datapoint and its sourrounding
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 $Occurrences
plot $Data u ((abs(x0-)<Delta) & (abs(y0-)<Delta) & (abs(z0-)<Delta) ? 1 : 0):(1) smooth frequency
unset table
# extract the number from $Occurrences which will be used to color the datapoint
set table $Dummmy
plot $Occurrences u (c0=,0):([=10=]) every ::1::1 with table
unset table
ColC[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",ColX[i],ColY[i],ColZ[i],ColC[i])
}
set print
TimeEnd = time(0.0)
print sprintf("Duration: %.3f sec",TimeEnd-TimeStart)
set palette rgb 33,13,10
splot $Data u 1:2:3:4 w p ps 1 pt 7 lc palette z notitle
set terminal gif animate delay 30
set output "Density.gif"
Amin = 40
Amax = 60
AFrames = 25
do for [i=0:AFrames] {
print sprintf("Frame %g, Angle: %.1f", i, sin(2*pi*i/AFrames)*(Amax-Amin)+Amin)
set view 45,(sin(2*pi*i/AFrames)*(Amax-Amin)+Amin)
replot
}
set output
应该导致:
我的数据文件是一组位于轴原点周围的 (x,y,z) 点。它们代表某种措施失败的点。 这些点在这个link.
Gnuplot 可以绘制它们,
set encoding iso_8859_1
set term postscript eps enhanced color size 4.7in,4in
set xlabel "X"
set ylabel "Y"
set zlabel "Z"
set output "test_gp.eps"
set style line 1 lc rgb '#0060ad' pt 7 ps 0.5 lt 1 lw 0.5 # --- blue
set style fill transparent solid 0.15 noborder
splot "data.dat" u 1:2:3 w p ls 1 title "P_{error}"
结果图
问题是图中没有显示错误更有可能发生的地方。 如果可能的话,我想展示点密度的变化。
我不知道是否可以改变点的颜色或赋予它们透明度并尝试表示点密度最高的位置。
如果无法表示 3D 点的密度,另一种方法是在三个平面 (x=0,y,z), (x,y=0) 中制作点的投影密度,z), (x,y,z=0)。
此致
编辑:
我可以用不同的颜色绘制实验的成功 (0
) 和错误 (1
) 点位置。此 link 中的文件有第 4 列,其中包含所有数据样本(0 和 1)。
splot
图
splot "data_all.dat" u 1:2:3:4 w points ls 1 palette title "P_{error}"
是
但是这个数字没有显示点的密度。 例如,在 Mathematica 中,这些数据样本的密度图是
如何使用 Gnuplot
获得密度图?。很可能 Mathematica 正在对中间的点进行插值并赋予它们介于 0 和 1 之间的值,但我不知道如何使用 Gnuplot 实现它。
@user1993416,我想你可以用 gnuplot 做点什么。您可能需要使用参数 Delta
。用我 8 岁的电脑 1000 点大约需要。 2分钟。
以下代码:
### 3D density plot
reset session
set term wxt
N = 1000 # number of datapoints
Delta = 2 # half boxwidth
TimeStart = time(0.0)
# create dummy some dummy data
set samples N
set table $Data
plot '+' u (invnorm(rand(0))):(invnorm(rand(0))):(invnorm(rand(0))) with table
unset table
# put the datafile/dataset into arrays
stats $Data nooutput
RowCount = STATS_records
array ColX[RowCount]
array ColY[RowCount]
array ColZ[RowCount]
array ColC[RowCount]
do for [i=1:RowCount] {
set table $Dummy
plot $Data u (ColX[[=10=]+1]=,0):(ColY[[=10=]+1]=,0):(ColZ[[=10=]+1]=,0) with table
unset table
}
# look at each datapoint and its sourrounding
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 $Occurrences
plot $Data u ((abs(x0-)<Delta) & (abs(y0-)<Delta) & (abs(z0-)<Delta) ? 1 : 0):(1) smooth frequency
unset table
# extract the number from $Occurrences which will be used to color the datapoint
set table $Dummmy
plot $Occurrences u (c0=,0):([=10=]) every ::1::1 with table
unset table
ColC[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",ColX[i],ColY[i],ColZ[i],ColC[i])
}
set print
TimeEnd = time(0.0)
print sprintf("Duration: %.3f sec",TimeEnd-TimeStart)
set palette rgb 33,13,10
splot $Data u 1:2:3:4 w p ps 1 pt 7 lc palette z notitle
set terminal gif animate delay 30
set output "Density.gif"
Amin = 40
Amax = 60
AFrames = 25
do for [i=0:AFrames] {
print sprintf("Frame %g, Angle: %.1f", i, sin(2*pi*i/AFrames)*(Amax-Amin)+Amin)
set view 45,(sin(2*pi*i/AFrames)*(Amax-Amin)+Amin)
replot
}
set output
应该导致: