0

Can somebody explain why the second curve is not just the expected line from 0,0 to 1,1, but a line from 0,0 to 2*pi,2*pi? Why is the second range [t=0:1] ignored? Bug or feature or did I miss anything in the manual?

Code:

### parametric curves
reset session

set parametric
set size square

plot [0:2*pi] cos(t), sin(t) w l, \
     [t=0:1] t, t w l
### end of code

Result:

enter image description here

3
  • 1
    Parametric mode is not relevant. gnuplot has never allowed axis range restrictions anywhere except the very start of a plot command. I advocate not placing them at the start either; use a separate "set range" command. You may be thinking of local sampling ranges introduced in version 5 to support pseudofiles '+' and '++'. Those only affect the sampling range, not the axis range. Commented Oct 21, 2019 at 21:42
  • thank you for your comment. Ok, in the above case with '+' it will work if you use the u 1:1 syntax. Then what is the difference between plot cos(t),sin(t) and plot '+' u (cos($1)):(sin($1)), except the first one is easier to write and read? The follow-up question would be: is it possible to have different samplings, e.g. first curve 1000 samples, second curve 10 samples? So far, I guess you can set samples only before the plot command and it will hold for all curves, right? Commented Oct 22, 2019 at 5:10
  • Parametric mode is no longer needed, although as you say it can be easier to read. Yes you can have different sampling ranges and intervals. E.g.splot '++' using 1:2:($1*25.*sin($2/10)), [u=30:70:5][v=0:50:2] '++' using 1:2:(u*v) Commented Oct 22, 2019 at 5:25

2 Answers 2

2

The use of axis ranges at the start of a plot command is a historical artifact. It confuses the program as well as the user, and since the introduction of sampling ranges in version 5 it leads to potentially ambiguous syntax. To disambiguate the syntax you can place the keyword sample in front of the range specifier for the first plot component:

set style data linespoints
set key left
plot sample [14:22:2] '+' u 1:1 pt "1" ti "sub-plot 1 sample interval 2", \
            [1:12:1]  '+' u 1:1 pt "2" ti "sub-plot 2 sample interval 1", \
            [33:66:6] '+' u 1:1 pt "3" ti "sub-plot 3 sample interval 6"

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! Ok, this clarifies a lot. And if you know what to search for you will also find this statement in the manual... help sampling 1D. Good to know.
2

Let me summarize my learnings, I'm a bit confused about ranges, samples and parametric.

What I wanted to achieve is the following:

3 curves with different ranges and different samples by one plot command. For example to illustrate:

  • Random: 1000 random points in the range [0:2][0:2]
  • Circle: Circle with radius 1 and 24 points in the range [-1:1][-1:1]
  • Line: Straight line with 3 samples in the range [-0.5:0.5][-0.5:0.5]

Learnings:

  1. if parametric is off, it does not not allow (gives an error) to specify [start:end:step] in the first plot command, whereas it is tolerated in the second and third (sub)plot-command. Strange.
  2. if parametric is on, the step in the first plot command will be ignored and number of samples will be defined by the previous set samples. Not so obvious.
  3. if parametric is off, I cannot achieve the desired result.
  4. I have to use set parametric together with [start:end:step] '+' u ...

Long story short. I can achieve the desired results when coding something like:

set parametric
set samples samples1   # because step1 will be ignored
plot [start1:end1:step1] '+' u (<whatever>):(<whatever>) ti "sub-plot 1", \
     [start2:end2:step2] '+' u (<whatever>):(<whatever>) ti "sub-plot 2", \
     [start3:end3:step3] '+' u (<whatever>):(<whatever>) ti "sub-plot 3"

The code and graph below show different options with/without parametric and different order of the 3 curves. Only the bottom row in the graph below shows the desired results.

Code:

 ### curves with different ranges & samples within one plot command
reset session
set colorsequence classic

Random      = "[0:1:0.001]    '+' u (2*rand(0)):(2*rand(0)) w p pt 7 ps 0.5 not"
RandomFirst = "[0:1]          '+' u (2*rand(0)):(2*rand(0)) w p pt 7 ps 0.5 not"
Circle      = "[0:2*pi:pi/12] '+' u (cos($1)):(sin($1)) w lp pt 7 not"
CircleFirst = "[0:2*pi]       '+' u (cos($1)):(sin($1)) w lp pt 7 not"
Line        = "[-0.5:0.5:0.5] '+' u 1:1 w lp pt 7 lw 2 not"
LineFirst   = "[-0.5:0.5]     '+' u 1:1 w lp pt 7 lw 2 not"

set multiplot layout 4,3 columnsfirst

    set label 1 "random/circle/line" at screen 0.166,0.99 center
    unset parametric
        set title "parametric OFF"
        plot @RandomFirst, @Circle, @Line
    set parametric
        set title "parametric ON"
        plot @Random, @Circle, @Line
    unset parametric
    set samples 1000
        set title "parametric OFF"
        plot @RandomFirst, @Circle, @Line
    set parametric
        set title "parametric ON"
        plot @Random, @Circle, @Line

    set label 2 "line/random/circle" at screen 0.5,0.99 center
    unset parametric
        set title "parametric OFF"
        plot @LineFirst, @Random, @Circle
    set parametric
        set title "parametric ON"
        plot @Line, @Random, @Circle
    set samples 3
    unset parametric
        set title "parametric OFF"
        plot @LineFirst, @Random, @Circle
    set parametric
        set title "parametric ON"
        plot @Line, @Random, @Circle


    set label 3 "circle/line/random" at screen 0.833,0.99 center
    unset parametric
        set title "parametric OFF"
        plot @CircleFirst, @Line, @Random, 
    set parametric
        set title "parametric ON"
        plot @Circle, @Line, @Random, 
    set samples 24
    unset parametric
        set title "parametric OFF"
        plot @CircleFirst, @Line, @Random, 
    set parametric
        set title "parametric ON"
        plot @Circle, @Line, @Random, 

    unset multiplot
### end of code

Result:

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.