Gnuplot version: 5.2 patchlevel 8
System: Linux subsystem on windows (Ubuntu 20.04 LTS)
I'm very new to gnuplot and am looking for a way to assign different colors to different parametric curves in 3D space so that the orientation of color gradient is across the curves. (Like 10 lines, different lines have different solid colors, but the colors make a discrete gradient as a whole)
For example; following equations define different trajectories on a unit sphere (please see the photo below).
x = cos(u) * cos(a*u)
y = cos(u) * sin(a*u)
z = sin(u)
with "u" being the polar angle between -pi and pi, and "a", some constant.
Here's what I've tried. It does give me color-gradient curves but the gradient is "along" the curves.
reset
set parametric
set angle degree
set urange [-90:90]
set vrange [0:360]
set xrange [-1:1]
set yrange [-1:1]
set zrange [-1:1]
set ticslevel 0
set xlabel "x"
set ylabel "y"
set zlabel "z"
set view equal xyz
set nokey
jmax = 20.0
set for [j=1:jmax] style line j lc palette frac j/jmax lw 2
fx(u,v)=cos(u)*cos(v)
fy(u,v)=cos(u)*sin(v)
fz(u)=sin(u)
a=0.2
splot for [j=1:jmax] fx(u,u*a*j), fy(u, u*a*j), fz(u) ls j
# splot for [j=1:jmax] fx(u,u*a*j), fy(u, u*a*j), fz(u) lc palette frac j/jmax
(Correction to the original question: Sorry, the last splot
line in the above code I posted was not what I actually tried so I commented it out and added the actual one I tried. The result is same and doesn't affect the question I believe.)
"show lines" command gives me the next output.
gnuplot> show lines
linestyle 1, linecolor palette fraction 0.05 linewidth 2.000 dashtype solid pointtype 1 pointsize default
linestyle 2, linecolor palette fraction 0.10 linewidth 2.000 dashtype solid pointtype 2 pointsize default
...
It appears that palette fraction
is set in the for
-loop as I intended, but somehow the color gradient seems to be mapped onto z-axis and I don't understand why it is so.
Does anyone have any idea?
Thank you very much in advance.
I do not know why the approach you show isn't working. It looks correct to me. But rather than debugging, I will suggest an alternative that uses the pseudofile '++'
rather than parametric mode. Your original three function provide the x, y, z coordinates (first three fields in the using
specification) and the fractional color goes in the fourth field of using
. The urange and vrange statements still apply to the coordinates generated for '++'
.
set angle degree
set urange [-90:90]
set vrange [0:360]
set xrange [-1:1]
set yrange [-1:1]
set zrange [-1:1]
set ticslevel 0
set xlabel "x"
set ylabel "y"
set zlabel "z"
set view equal xyz
set nokey
fx(u,v)=cos(u)*cos(v)
fy(u,v)=cos(u)*sin(v)
fz(u)=sin(u)
a=0.2
jmax = 20.
set dummy d
splot for [j=1:jmax] '++' using (fx(d,d*a*j)) : (fy(d, d*a*j)) : (fz(d)) : (j/jmax)\
with lines lc palette