在gnuplot中绘制3D热图 [英] Plotting 3D heatmap in gnuplot
问题描述
我有4D数据.需要将第四列表示为颜色强度.其他三列将代表三个不同的轴.我想使用gnuplot生成3D热图.我怎样才能做到这一点?
I have a 4D data. The forth column is needed to be represented as color intensity. The other three columns will represent three different axes. I want to generate 3D heatmap using gnuplot. How can I do this?
数据样本:
0 0 0 16
0 0 1 25
0 1 0 27
0 1 1 29
1 0 0 8
1 0 1 44
1 1 0 50
1 1 1 27
推荐答案
在gnuplot中生成3D热图与生成2D热图相同,只不过您在中使用
添加了另一列.换句话说,数据文件布置了一系列扫描",相邻的扫描"以四边形连接.例如
generating a 3D heatmap in gnuplot is the same as generating a 2D heatmap except you add an additional column to using
. In other words, the datafile lays out a series of "scans" and adjacent "scans" are connected with quadrilaterals. e.g.
x1 y1 z11 c11
x1 y2 z12 c12
x1 y3 z13 c13
...
x1 yN z1N c1N
#blank line here
x2 y1 z21 c21
x2 y2 z22 c22
...
x2 yN z2N c2N
#blank line here
.
.
.
#blank line here
xN y1 zN1 cN1
xN y2 zN2 cN2
...
xN yN zNN cNN
现在您可以使用在'pm3d上以1:2:3:4 w pm3d
绘制'datafile'来绘制图形.
Now you can plot this using splot 'datafile' u 1:2:3:4 w pm3d
.
*请注意,沿着特定扫描"方向的x值不必恒定不变-刚开始时以这种方式可视化就更容易了.
*Note that the x-values along a particular "scan" don't need to be constant -- It's just easier to visualize it that way at first.
作为一个非常简单的示例,我们可以使用 ++
特殊文件:
As a very simple example, we can use the ++
special file:
set xrange [0:2*pi]
set yrange [0:2*pi]
splot '++' using 1:2:2:(sin($1)*sin($2)) with pm3d
您可以通过以下伪代码制作相同的数据文件:
You could make the same datafile via the following pseudocode:
do iy=0, ny
y = (2*pi/ny)*iy
do ix=0, nx
x = (2*pi/nx)*ix
z = y
write x,y,z,sin(x)*sin(y)
enddo
write blank space
enddo
这篇关于在gnuplot中绘制3D热图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!