基本上,我想通过参数splot
绘制彩色球形(下图,上图)。但是,我找不到一种方法来使它们的颜色均匀,但是每个球体的颜色都不同。
我发现了这篇文章(Gnuplot, pm3d and surfaces),使我很难做到这一点,方法是先将球体绘制到数据块上,然后再绘制移位的数据块(下图,中间)。
现在,我想添加一些行。但是,球体的颜色意外地改变了它们的颜色(下图,底部)。 为什么?如何避免?如何保留原本打算的颜色?
我的代码:
### connected 3D-spheres with splot and pm3d
reset session
set obj 1 rect from screen 0,0,0 to screen 1,1,0 behind
set obj 1 rect fc rgb "black" fs solid 1.0
set view equal xyz
set view 45,45
unset border
unset tics
unset colorbox
set style fill solid 1.0 noborder
set pm3d depthorder noborder
set pm3d lighting specular 0.5
set isosamples 50,50
set parametric
set urange [-pi/2:pi/2]
set vrange [0:2*pi]
Radius = 1
set table $Sphere
splot Radius*cos(u)*cos(v), Radius*cos(u)*sin(v), Radius*sin(u)
unset table
unset parametric
$Pos <<EOD
0 0 0
4 0 0
4 4 0
0 4 0
EOD
$Bonds <<EOD
0 0 0
4 0 0
4 0 0
4 4 0
4 4 0
0 4 0
0 4 0
0 0 0
EOD
PosX(i) = word($Pos[i],1)
PosY(i) = word($Pos[i],2)
PosZ(i) = word($Pos[i],3)
set palette defined (1 'red', 2 'green', 3 'blue', 4 'yellow')
set multiplot layout 3,1
set parametric
splot for [i=1:4] Radius*cos(u)*cos(v)+PosX(i), Radius*cos(u)*sin(v)+PosY(i), \
Radius*sin(u)+PosZ(i) with pm3d not
unset parametric
unset obj 1
splot \
for [i=1:4] $Sphere u ($1+PosX(i)):($2+PosY(i)):($3+PosZ(i)):(i) with pm3d not
splot \
for [i=1:4] $Sphere u ($1+PosX(i)):($2+PosY(i)):($3+PosZ(i)):(i) with pm3d not,\
$Bonds u 1:2:3 w l lw 4 lc rgb "grey" not
unset multiplot
### end of code
结果:
答案 0 :(得分:1)
这是第二种解决方案,不涉及设置调色板。 请注意,这需要gnuplot(版本5.3)的开发分支中的功能。它会在将来的稳定版本中出现,但尚未在5.2.6版中出现。
[如上所述的初步准备,然后是]
set palette defined (1 'red', 2 'green', 3 'blue', 4 'yellow')
set style line 1 lc 'red'
set style line 2 lc 'green'
set style line 3 lc 'blue'
set style line 4 lc 'yellow'
set multiplot layout 1,3
set parametric
splot for [i=1:4] Radius*cos(u)*cos(v)+PosX(i), Radius*cos(u)*sin(v)+PosY(i), \
Radius*sin(u)+PosZ(i) with pm3d not
unset parametric
unset obj 1
splot \
for [i=1:4] $Sphere u ($1+PosX(i)):($2+PosY(i)):($3+PosZ(i)):(i) with pm3d not
splot \
for [i=1:4] $Sphere u ($1+PosX(i)):($2+PosY(i)):($3+PosZ(i)) with pm3d fc ls i not,\
$Bonds u 1:2:3 w l lw 4 lc rgb "grey" not
unset multiplot
with pm3d fc lt i
也可以(线型而不是线型)