restrain the plotted fitting line to a certain interval within the plot (not the data; i already chose them) [duplicate]

StackOverflow https://stackoverflow.com/questions/17117489

  •  31-05-2022
  •  | 
  •  

Frage

i´m plotting a Dataset and performed two linear fit on the resulting graph. I plotted the results and got a graph with two straight lines. The two lines run from one end of the plot to the other. Do somebody know how to restrain the plot of the lines to a certain interval.

For example: the line of the first fit runs from x=800:1100 and the line of the second fit runs from x=900:1600.

The parameters of the whole plot are y= -2:9; x= 800:1600

War es hilfreich?

Lösung

You can use the fact that gnuplot ignores expressions like 1/0 and define a sort of indicator function:

f1(x) = 2.0*x + 1.0
f2(x) = x/3.0 + 2.0
ind(x, A, B) = 1.0/((x>A)*(x<B))

plot [800:1600] f1(x)*ind(x, 800, 1100), f2(x)*ind(x, 900, 1600)
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top