Reputation: 25714
Basically, I want to draw colored spheres via parametric splot
(image below, top). However, I couldn't find a way to make them uniform in color but each sphere with a different color.
I found this post (Gnuplot, pm3d and surfaces) which tought me to achieve it by plotting the spheres to a datablock first and then plot the shifted datablock (image below, middle).
Now, I want to add some lines. But then the colors of the spheres unexpectedly change their color (image below, bottom). Why? How to avoid? How can I keep the originally intended colors?
My code:
### 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
The result:
Upvotes: 2
Views: 911
Reputation: 15093
Here's a 2nd solution that doesn't involve setting up the palette. Note that this requires a feature from the development branch of gnuplot (version 5.3). It will appear in a future stable release but is not yet in version 5.2.6.
[preliminaries as above, followed by]
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
would also work (linetypes rather than linestyles)
Upvotes: 1