Reputation: 75
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?
Data Sample:
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
Upvotes: 0
Views: 4120
Reputation: 310227
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
Now you can plot this using splot 'datafile' u 1:2:3:4 w pm3d
.
*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
Upvotes: 1