Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to specify different range for multiple functions in the same plot

1,792 views
Skip to first unread message

Peng...@gmail.com

unread,
Mar 26, 2007, 3:51:09 PM3/26/07
to
Hi,

plot [0:10] x, [-10:10] -x

Suppose I want to plot two different functions with different xrange.
Is it possbile to do it in gnuplot directly, if know the explicit form
for each functions?

Or I have to right data for each function into files and plot from
these files?


Thanks,
Peng

Steve Bickerton

unread,
Mar 26, 2007, 4:06:52 PM3/26/07
to
Hi PengYu,

> plot [0:10] x, [-10:10] -x

> Suppose I want to plot two different functions with different xrange.

You can do this with the ternary operator (see 'help ternary'). Try the
following (based on your example above):

set xrange [-10:10]
g(x,min,max)=( (x>=min && x<=max)? 1.0 : (1/0) )
plot x*g(x,0,10) with line, -x*g(x,-10,10) with line


If you're finding that the lines don't quite meet at the boundaries, try
increasing 'samples' to 200.

set samples 200


Hope that helps,
steve

Hans-Bernhard Bröker

unread,
Mar 26, 2007, 5:03:34 PM3/26/07
to
Peng...@gmail.com wrote:

> Suppose I want to plot two different functions with different xrange.
> Is it possbile to do it in gnuplot directly, if know the explicit form
> for each functions?

Not quite.

> Or I have to right data for each function into files and plot from
> these files?

No. There are two alternatives:

1) plotting a function, but setting its value to "undefined" where you
don't want it plotted. See Steve Bickerton's earlier answer.

2) The generic "strange curve plotting cure": parametric mode

set parametric
set trange [0:1]
x1(t)=-10+10*t
x2(t)=-10+20*t

plot x1(t), f1(x1(t)) title "f1(x)", \
x2(t), f2(x2(t)) title "f2(x)"

0 new messages