Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gnuplot for loop with increment smaller then 1

Tags:

gnuplot

I was trying to plot the following

plot for [h=0:2:0.1] sin(h*x)

But it gives the following error

gnuplot> plot for [h=0:2:0.1] sin(x*h)
                     ^
         Expecting iterator     for [<var> = <start> : <end> {: <incr>}]
         or for [<var> in "string of words"]

But the following line works just fine

plot for [h=0:2:1.1] sin(x*h)

Is this a bug or it is supposed to work this way? I mean, why it is not accepting increments smaller than 1?

I'm using the following version of gnuplot

G N U P L O T
Version 5.0 patchlevel 1    last modified 2015-06-07 
like image 519
McLeary Avatar asked Oct 20 '15 18:10

McLeary


1 Answers

Gnuplot supports iterations only with integer values (see documentation section "For loops in plot command", p 98). Values smaller then 1 are casted as integer to 0, which is not allowed. Using e.g.

plot for [h=0:3:1.5] sin(x*h) title sprintf('%.1f', h)

plots four curves with h having the values 0, 1, 2, 3. To use smaller values you must scale the iteration value later:

plot for [h=0:20:1] sin(0.1*h*x)
like image 143
Christoph Avatar answered Nov 02 '22 21:11

Christoph