如何绘制(x,y,z)点以显示其密度 [英] How to plot (x,y,z) points showing their density
问题描述
我的数据文件是围绕轴原点的一组(x,y,z)点。它们代表一种措施失败的点。
这些点位于此
问题是该图未显示出错误的出处可能发生。
如果可能的话,我想显示点密度的变化。
我不知道是否可以改变点的颜色点或赋予它们透明性,并尝试表示密度最高的位置。
如果无法表示3D点的密度,则可以采用另一种方法在三个平面(x = 0,y,z),(x,y = 0,z),(x,y,z = 0)中绘制点的投影密度。
致谢
编辑:
我可以用不同的颜色绘制成功点( 0
)和错误点( 1
)的位置我的实验。此
,但该图未显示点的密度。
例如,在Mathematica中,这些数据样本的密度图为
如何使用 Gnuplot
获得密度图? Mathematica可能正在对中间的点进行插值并将其值设置为0到1之间,但我不知道如何使用Gnuplot来实现。
@ user1993416,我想您可以使用gnuplot做一些事情。您可能需要使用参数 Delta
。使用我8岁的计算机,大约需要1000点积分。 2分钟。
关注代码:
### 3D密度图
重置会话
设置项wxt
N = 1000#数据点数量
Delta = 2#半框宽度
TimeStart = time(0.0)
#创建虚拟对象一些虚拟数据
设置样本N
设置表$ Data
图'+'u(invnorm(rand(0))):( invnorm (rand(0))):( invnorm(rand(0)))与表
取消表
#将数据文件/数据集放入数组
stats $ Data nooutput
RowCount = STATS_records
数组ColX [RowCount]
数组ColY [RowCount]
数组ColZ [RowCount]
数组ColC [RowCount]
为[i = 1:RowCount] {
设置表格$ Dummy
图$ Data u(ColX [$ 0 + 1] = $ 1,0):( ColY [$ 0 + 1] = $ 2,0):( ColZ [$ 0 + 1] = $ 3,0),其中表
未设置表
}
#查看每个数据点及其周围的
为[i = 1: RowCount] {
print sprintf( Datapoint%g of%g,i,RowCount)
x0 = ColX [i]
y0 = ColY [i]
z0 = ColZ [i]
#计算距离感兴趣数据点周围$ Delta的数据点
设置表$ Occurrences
图$ Data u((abs(x0- $ 1)< Delta) & (abs(y0- $ 2)< Delta)& (abs(z0- $ 3)< Delta)? 1:0):( 1)平滑频率
未设置表
#从$ Occurrences中提取数字,该数字将用于为数据点
设置表着色$ Dummmy
图$ Occurrences u(c0 = $ 2,0):($ 0)每个:: 1 :: 1,其中表
未设置表
ColC [i] = c0
}
#再次将数组放入数据集中
set print $ Data
做[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)
设置调色板rgb 33,13,10
splot $ Data u 1:2: 3:4 wp ps 1 pt 7 lc调色板z notitle
设置终端gif动画延迟30
设置输出 Density.gif
Amin = 40
Amax = 60
AFrames = 25
[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
}
设置输出
应导致:
My data file is a set of (x,y,z) points located around the axis origin. They represent points where a kind of measure has failed. These points are in this link.
Gnuplot can plot them,
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}"
with the resulting plot
The problem is that the figure does not show where the error is more likely to occur. I would like to show the variations in the density of points if it is possible.
I do not know if it is possible to vary the color of the points or give them transparency and try to represent the locations with the most density of points.
If a representation of the density of 3D points is not possible, another way could be to make a projection density of the points in the three planes (x=0,y,z), (x,y=0,z), (x,y,z=0).
Regards
EDIT:
I can plot with different colors the success (0
) and error (1
) point locations of my experiment. The file in this link has a 4th column with all data samples ( 0's and 1's).
The splot
figure
splot "data_all.dat" u 1:2:3:4 w points ls 1 palette title "P_{error}"
is
but this figure is not showing the density of points. For example, in Mathematica the density plot of these data samples is
How could I get the density plot with Gnuplot
?. It is likely that Mathematica is doing an interpolation of the points in the middle and give them values between 0 and 1, but I do not know how to achieve it with Gnuplot.
@user1993416, I guess you can do something with gnuplot. You might need to play with the parameter Delta
. With my 8 year old computer 1000 points need approx. 2 minutes.
The followig code:
### 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[$0+1]=$1,0):(ColY[$0+1]=$2,0):(ColZ[$0+1]=$3,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-$1)<Delta) & (abs(y0-$2)<Delta) & (abs(z0-$3)<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=$2,0):($0) 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
should result in:
这篇关于如何绘制(x,y,z)点以显示其密度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!