问题
I want to make a 3D representation of a large number of spheres of different diameter using gnuplot and whose information are in a file called 'data.dat'
. If I do:
splot 'data.dat' u 1:2:3 w p lt 7
I get a series of points of small dimensions of a homogeneous color. How can I add the real size of the spheres (read from the 4th column of the file 'data.dat'
) using the splot
command? Something like:
splot 'data.dat' u 1:2:3:4 ...
回答1:
Since gnuplot 5.4, I guess you have the plotting style with circles
also in 3D, before, it was limited to 2D plots.
If you have an older gnuplot version you could do something like:
splot 'data.dat' u 1:2:3:4 w p pt 7 ps var notitle
This will plot points with variable size. However, you asked for "real" size. You might workaround this with scaling the 4th column with some factor. Something like:
Factor = 0.123
splot 'data.dat' u 1:2:3:($4*Factor) w p pt 7 ps var notitle
The following works only for gnuplot >=5.4:
Code:
### plot with circles in 3D (only for gnuplot >=5.4)
reset session
# create some test data
set print $Data
do for [i=1:100] {
print sprintf("%g %g %g %g %g", rand(0), rand(0), rand(0), rand(0)*0.02+0.02, int(rand(0)*0xffffff))
}
set print
set view 60,30,1.25
set view equal xyz
set xyplane at 0
set tics 0.2
set style fill solid 0.5
splot $Data u 1:2:3:4:5 w circles lc rgb var notitle
### end of code
Result:
来源:https://stackoverflow.com/questions/64481381/gnuplot-how-to-plot-homogeneous-spheres-in-3d-with-different-diameters