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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With