Discussion:
On ranges in gnuplot
Andrey V. Komolkin
2007-03-17 18:40:34 UTC
Permalink
Dear colleagues,

I am frequent user and enthusiast of "gnuplot", but not a developer. Let
me propose some new features for the program. I hope these are new,
because I did not find any references to such features in documentation
for new version 4.3.

---------------

First. In the "plot" command I propose to allow to setup range of 'x'
(independent) variable to each of functions/files. For instance:

set xrange [0:10]
plot sin(x), cos(x) range [1:9], 'file.dat' range [1:9] with lines

In this example, sin(x) should be shown in range [0:10], but cos(x) and
data from 'file.dat' in different ranges, which are set individually for
these graphs. This may be useful in the case we like to plot tabulated
data and its approximation (analytical function) in the same plot.

Imagine, the data we like to approximate have two parts:

f1(x)=a*x+b
fit [0:5] f1(x) 'file.dat' via a,b
f2(x)=c*x+d
fit [6:10] f2(x) 'file.dat' via c,d
set xr [0:10]
plot 'file.dat' w p, [0:5] f1(x), [6:10] f2(x)

I do not like to plot analytical function f1(x) outside the range [0:5],
where it was fitted and (in general) defined. And vice versa, f2(x) was
defined in range [6:10]...

-----------------

Second. Let me propose "dashed" ranges: [0:10,20:30]. This feature may be
useful for approximation of experimental data.

Imagine, experimental data g(x) contains several peaks f(x) on the
"basement" -0.02*x+1.0. We need to remove trend (-0.02*x+1.0) from the
data.

set xr [-10:10]
set yr [0:7]
f(x,a,x0,dx)=a*exp(-(x-x0)**2/dx**2)
g(x)=f(x,5,1,1)+f(x,2,-3,0.5)+1.0-0.02*x

This trend can not be determined on the whole range [-10:10],
but on two ends of the range:

t(x)=a*x+b
fit [*:-5,5:*] t(x) 'file.dat' via a,b
set xr [-10:10]
plot t(x) range [-10:-5,5:10], 'file.dat' with points

------------------

Conclusion. I proposed in this letter two new features for the 'gnuplot'.

First: separate ranges for each functions/files in 'plot' command

Second: "dashed" ("united" or however it will be called) ranges which
consist of several (two, three or even more) subranges.

------------------

I like to receive comments on my proposals.

Best wishes,

Andrei Komolkin.
======================================================================
Dr. Andrei V. Komolkin
Senior Lecturer (University Reader)

V. A. Fock Institute of Physics Tel.: +7-(812)-428-44-79
Saint-Petersburg State University Fax: +7-(812)-428-72-40
198504, Saint-Petersburg E-mail: ***@esr.phys.spbu.ru
Russia
Lutz Maibaum
2007-03-18 01:11:26 UTC
Permalink
Dear Andrey,

I believe the features you are proposing might already be available in
gnuplot, albeit with a less concise syntax.
Post by Andrey V. Komolkin
First. In the "plot" command I propose to allow to setup range of 'x'
set xrange [0:10]
plot sin(x), cos(x) range [1:9], 'file.dat' range [1:9] with lines
This can be done using

set xrange [0:10]
plot sin(x), (x >= 1 && x <= 9 ? cos(x) : 1/0), 'file.dat' using 1:($1 >= 1
&& $1 <= 9 ? $2 : 1/0) with lines

(This assumes that file.dat contains rows of (x,y) pairs. If instead it
contains rows of single numbers, replace $1 by $0 and $2 by $1).
Post by Andrey V. Komolkin
f1(x)=a*x+b
fit [0:5] f1(x) 'file.dat' via a,b
f2(x)=c*x+d
fit [6:10] f2(x) 'file.dat' via c,d
set xr [0:10]
plot 'file.dat' w p, [0:5] f1(x), [6:10] f2(x)
Try

plot 'file.dat' w p, (x >= 0 && x <= 5 ? f1(x) : 1/0), (x >= 6 && x <= 10 ?
f2(x) : 1/0)
Post by Andrey V. Komolkin
Second. Let me propose "dashed" ranges: [0:10,20:30]. This feature may
be useful for approximation of experimental data.
t(x)=a*x+b
fit [*:-5,5:*] t(x) 'file.dat' via a,b
set xr [-10:10]
plot t(x) range [-10:-5,5:10], 'file.dat' with points
t(x)=a*x+b
fit t(x) 'file.dat' using 1:($1 < -5 || $1 > 5 ? $2 : 1/0) via a,b
set xr [-10:10]
plot (x < -5 || x > 5 ? t(x) : 1/0), 'file.dat' with points

You can find the details in "help using" and "help ternary".

Hope this helps,

Lutz

Continue reading on narkive:
Loading...