# Different x range gnuplot

1. Dec 27, 2013

### sketos

Hello,

How can i plot some data points in gnuplot and in the same plot a function, for example
f(x)=0.2*x**(-0.6)
plot [0:6] "data.dat" with errorbars, [0:2] f(x)

2. Dec 27, 2013

### Simon Bridge

The same way you normally plot - what's the problem?
(the meaning of your ranges is not clear though)

Last edited: Dec 27, 2013
3. Dec 27, 2013

### D H

Staff Emeritus
Do you want x=2 on your f(x) plot to correspond to x=2 or x=6 on your data plot?

If it's the former, just plot it normally. The data plot will fill the plot, while the plot of f(x) will only occupy in the leftmost third of the plot.

If it's the latter you are asking for, define an xrange to be used for your data plot and an x2range to be used for your f(x) plot. Then plot with plot "data.dat" axes x1y1 with error bars, f(x) axes x2y1. If you want, you can make a separate y2range for your f(x), too. Be careful, though. Plots are often at their best when they are simple.

4. Dec 27, 2013

### sketos

i tried your method by setting different x1,x2 axes but then a new problem arrises. Somehow the function f(x) dispaces.
What i am trying to do is fit a power function to the data , but not all of them. When i do

set xrange [0:6]
plot "data.dat" with errorbars,f(x)

the plot looks good but when i use
set xrange [0:6]
set x2range [0:1]

plot "data.dat" axes x1y1 with errorbars, f(x) axes x2y1

the function takes other values at y-axis , i can explain why!

5. Dec 27, 2013

### sketos

when i say it looks good i mean it fits good with the data but extends in the whole x-range, something that i dont want to happen

6. Dec 27, 2013

### D H

Staff Emeritus
Of course it does. That's the whole point of setting an x2range.

You did not try my method because the very first step in my method was for you to answer my question Do you want x=2 on your f(x) plot to correspond to x=2 or x=6 on your data plot? It also appears you did not read the gnu plot documentation on what x2range does. Read the fine documentation! Always!

It appears you want only one x axis, not two, but you want your f(x) only to be plotted for values of x between 0 and 2. You cannot use plot [0:6] "data.dat", [0:2] f(x). It's illegal syntax. The range applies to all entities to be plotted.

What you can do is define another function, call it g(x). g(x) is one for x between 0 and 2, undefined for x>2. Then f(x)*g(x) is just f(x) for x≤2, but is undefined (and hence not plotted) for x>2.
Code (Text):
g(x)=( (x<=2)? 1.0 : (1/0) )
plot [0:6] "data.dat" with errorbars, f(x)*g(x)