gnuplot: How to plot homogeneous spheres in 3D with different diameters?

亡梦爱人 提交于 2021-01-06 02:49:26

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!