问题
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:
回答1:
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"
回答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:
- 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. - if
parametric
is on, thestep
in the first plot command will be ignored and number of samples will be defined by the previousset samples
. Not so obvious. - if
parametric
is off, I cannot achieve the desired result. - 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:
来源:https://stackoverflow.com/questions/58493814/gnuplot-how-to-set-multiple-ranges-in-parametric-plots