1
votes

plz help! i have a dataset with the format of

x   y   z   p 

-0.574142 -0.818671 0.011756 0.000440

-0.364919 0.184603 0.912555 0.000324

-0.990822 -0.022168 0.133345 0.000419

-0.983317 -0.089955 0.158099 0.000417

-0.493497 0.474422 -0.728961 0.000501

-0.789287 -0.566719 0.236336 0.000413

0.293932 0.520691 -0.801551 0.000510

and they are random points on a 3d sphere, with the p value (the fourth column) representing the "heat" of that location, the actual datafile is with 50 such points.

i want to plot the surface of the sphere into a heatplot, not each point being colored.

i've searched for lots of post, all of them would require some kind of isoline, but in my case there isn't any. is it possible still using gnuplot to do heatmap? i'm also opened to any other way.

btw im running linux with newest gnuplot, the data are generated by c

ps: i understand theres a way of making data into isolines and then use gnuplot with pm3d, but i cant do that because all my x data is randomized, hence there is no isoline.

1
Does this answer your question? Plotting 3D heatmap in gnuplotceving

1 Answers

2
votes

Note: This answer is only relevant to the newest gnuplot, version 5.4

Gnuplot version 5.4 can work in a 3D grid space of voxels, The voxel values can be used to hold a 4th dimension of data. I.e voxel(x,y,z) = value This is a very new feature and could be improved, so your question serves as a nice example to show what it can and cannot do right now.

$data << EOD
  x   y   z   p
-0.574142 -0.818671 0.011756 0.000440
-0.364919 0.184603 0.912555 0.000324
-0.990822 -0.022168 0.133345 0.000419
-0.983317 -0.089955 0.158099 0.000417
-0.493497 0.474422 -0.728961 0.000501
-0.789287 -0.566719 0.236336 0.000413
 0.293932 0.520691 -0.801551 0.000510
EOD
    
#
# Generate a heatmap on the surface of a sphere
#
set view equal xyz
set view 78, 246
set xyplane at 0
unset key
set xtics ("x" 0); set ytics ("y" 0); set ztics ("z" 1)
set hidden3d    # only relevant to axis tics and labels

#
# Use spherical mapping to generate a set of points describing the surface.
# Then return to Cartesian coordinates to handle voxels.
#
set mapping spherical
set angle degrees
set samples 51
set isosamples 101
set urange [-90:90]
set vrange [0:360]
set table $surface
splot '++' using 1:2:(1.0) with points
unset table
set mapping cartesian

# define 100 x 100 x 100 voxel grid
rlow = -1.1; rhigh = 1.1
set xrange [rlow:rhigh]; set yrange [rlow:rhigh]; set zrange [rlow:rhigh]
set vgrid $vdensity size 100
vclear $vdensity

# mark voxels in a spherical region with radius <near> around each point in $data
# Note that values are summed rather than averaged
near = 0.1
vfill $data skip 1 using 1:2:3:(near):($4)
show vgrid

# color range should be found automatically but it isn't
set cbtics
set colorbox user origin screen 0.8, screen 0.2
set cbrange [ 0 : 0.001 ]
set palette cubehelix negative   # colors from cbmin white -> cbmax dark

set pm3d depthorder
set pm3d lighting primary 0.4 specular 0.1

set title "Sphere surface is colored by the value of the nearest point[s] in $data"
splot $surface using 1:2:3:(voxel($1,$2,$3)) with pm3d

enter image description here