Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restricting the domain of a function plotted on Gnuplot

Tags:

gnuplot

I am plotting a set of data on Gnuplot, and want to superimpose the function x^2 on the same plot. I can do this like so:

plot "filename" using 1:2, x**2

Which produces a plot in which the function x^2 stretches across the whole domain of the graph. I would like to make it such that the function is only shown on a small stretch of the graph, say from x=1 to x=2, while the size of the graph is dictated by filename to be from x=0 to x=10. I know that to plot the function by itself I could do:

plot [1:2] x**2

But how would I keep the superimposition together, given that what I tried intuitively did not work:

plot "filename" using 1:2, [1:2] x**2

invalid expression

The documentation seems to be hard to interpret when it comes to getting this to work.

like image 704
dplanet Avatar asked Jan 11 '13 02:01

dplanet


1 Answers

The easiest way may be to define a piecewise function using the ternary operator ?:

f(x) = (x > 1 && x < 2) ? x**2 : 1/0
plot "filename" using 1:2, f(x)

Another way is with the replot command:

plot "filename" using 1:2
replot [1:2] x**2
like image 122
andyras Avatar answered Sep 28 '22 01:09

andyras