Plotting two parametric functions in Gnuplot with two command lines separated by a ',\'?

Viewed 64

When plotting functions of a single variable, I can plot multiple functions with a command of the form

plot  x ti "first function",\
      x**2.0 ti "second function"

I would like to do the same thing with a parametric plot, but this does not work in the example that I am interested in. I produced a minimal working example for you:

K = 360.0/(2.0*pi);
k = 1.0/K;

xe(lambda) =  (-1.0) * ( ((0.0 <= lambda) & (lambda < 180.0)) ? lambda: lambda - 360.0 )*k
ye(phi) = (log(1./cos(phi*k) + tan(phi*k)))

set parametric
set multiplot

PHI(t, d, GHA, omega) =pi/2.-acos(cos(omega) * sin(d)-cos(d) * cos(t) * sin(omega))
LAMBDA(t, d, GHA, omega) = ( lambda = -(atan((-sin(GHA) * (cos(d)* cos(omega)+cos(t) * sin(d) * sin(omega))+cos(GHA) * sin(omega) * sin(t))/(cos(d) * cos(GHA) * cos(omega)+sin(omega)*  (cos(GHA) * cos(t) * sin(d)+sin(GHA)* sin(t)))) + (cos(d)* cos(GHA)* cos(omega) +  sin(omega) * (cos(GHA)* cos(t) * sin(d) + sin(GHA)  *sin(t)) >0.0 ? 0.0 : pi)) , lambda - 2.0*pi*floor(lambda/(2.0*pi)))

lambda_min = 170;
lambda_max = 190;
phi_min = 310;
phi_max = 80;

set xrange [xe(lambda_min):xe(lambda_max)]
set yrange [ye(phi_min):ye(phi_max)]

plot [0.:2.09 ] xe(K*LAMBDA(t, 0.46, 4.63, 1.25)), ye(K*PHI(t, 0.46, 4.63, 1.25)) lt 1 linecolor rgb "red" ti "A" ,\
[2.09:2.*pi] xe(K*LAMBDA(t, 0.46, 4.63, 1.25)), ye(K*PHI(t, 0.46, 4.63, 1.25))  lt 1 linecolor rgb "blue" ti "B"

On

Gnuplot Version 5.4 patchlevel 2 last modified 2021-06-01

this yields the following plot: enter image description here where the curves "A" and "B" overlap.

However, if I split the plotting command into separate lines by replacing the last two lines with

plot [0.:2.09 ] xe(K*LAMBDA(t, 0.46, 4.63, 1.25)), ye(K*PHI(t, 0.46, 4.63, 1.25)) lt 1 linecolor rgb "red" ti "A"
plot [2.09:2.*pi] xe(K*LAMBDA(t, 0.46, 4.63, 1.25)), ye(K*PHI(t, 0.46, 4.63, 1.25))  lt 1 linecolor rgb "blue" ti "B"

then I get this plot enter image description here.

I would like to obtain the second graphical result by keeping the first plot command

plot [0.:2.09 ] xe(K*LAMBDA(t, 0.46, 4.63, 1.25)), ye(K*PHI(t, 0.46, 4.63, 1.25)) lt 1 linecolor rgb "red" ti "A" ,\
[2.09:2.*pi] xe(K*LAMBDA(t, 0.46, 4.63, 1.25)), ye(K*PHI(t, 0.46, 4.63, 1.25))  lt 1 linecolor rgb "blue" ti "B"

and without altering the other elements in the script (even though they may seem useless in the mimimal working example, they are needed for the actual, non-minimal plot which I would like to do).

How can I do this? Thanks!

1 Answers

The following seems to work for me. It uses the special filename '+' within the desired parametric ranges, check help special-filenames and help sampling 1D.

Code:

### parametric curve
reset session

K = 360.0/(2.0*pi);
k = 1.0/K;

xe(lambda) =  (-1.0) * ( ((0.0 <= lambda) & (lambda < 180.0)) ? lambda: lambda - 360.0 )*k
ye(phi)    = (log(1./cos(phi*k) + tan(phi*k)))

PHI(t, d, GHA, omega)    =  pi/2.-acos(cos(omega) * sin(d)-cos(d) * cos(t) * sin(omega))
LAMBDA(t, d, GHA, omega) = ( lambda = -(atan((-sin(GHA) * (cos(d)* cos(omega)+cos(t) * sin(d) * sin(omega))+cos(GHA) * sin(omega) * sin(t))/(cos(d) * cos(GHA) * cos(omega)+sin(omega)*  (cos(GHA) * cos(t) * sin(d)+sin(GHA)* sin(t)))) + (cos(d)* cos(GHA)* cos(omega) +  sin(omega) * (cos(GHA)* cos(t) * sin(d) + sin(GHA)  *sin(t)) >0.0 ? 0.0 : pi)) , lambda - 2.0*pi*floor(lambda/(2.0*pi)))

lambda_min = 170
lambda_max = 190
phi_min    = 310
phi_max    = 80

set xrange [xe(lambda_min):xe(lambda_max)]
set yrange [ye(phi_min)   :ye(phi_max)]
set parametric

plot [t=0   :2.09] '+' u (xe(K*LAMBDA(t, 0.46, 4.63, 1.25))):(ye(K*PHI(t, 0.46, 4.63, 1.25))) w l lc rgb "red"  ti "A" ,\
     [t=2.09:2*pi] '+' u (xe(K*LAMBDA(t, 0.46, 4.63, 1.25))):(ye(K*PHI(t, 0.46, 4.63, 1.25))) w l lc rgb "blue" ti "B"
### end of code

Result:

enter image description here

Related