2

I am trying to do a piecewise linear fit in (bash heredoc/script for) gnuplot. I tried this :

plot "datafile1" u 1:2:6:7:10:11 with xyerrorbars,\
     "datafile1" u 1:4:8:9:10:11 with xyerrorbars,\
     "datafile2" u 1:2:3 with xyerrorbars,\
     [xmin:xmax] f(x)

but it returns an invalid expression error. Any ideas why this fails?

note - fit [xmin:xmax] f(x) does not return any error messages (so I assume it works).

GNUPLOT 4.4.3

Christoph
  • 47,569
  • 8
  • 87
  • 187
Golam
  • 35
  • 3

1 Answers1

1

You are only allowed to specify a range at the beginning of the plot command. This range applies to all of the following, comma-delimited parts of this plot command. So you could use

plot [xmin:xmax] f(x),\
     "datafile1" u 1:2:6:7:10:11 with xyerrorbars

But that would apply the [xmin:xmax] range also to the datafile1. If you only want to limit the range of f(x), you must define a function which is invalid (1/0) outside of the desired range:

plot "datafile1" u 1:2:6:7:10:11 with xyerrorbars,\
     "datafile1" u 1:4:8:9:10:11 with xyerrorbars,\
     "datafile2" u 1:2:3 with xyerrorbars,\
     (x > xmin && x < xmax) ? f(x) : 1/0

Note, that your original command will work in the upcoming gnuplot version 5.0

Christoph
  • 47,569
  • 8
  • 87
  • 187
  • Thanks. Sorry to nag but, would this imply that this answer (http://stackoverflow.com/questions/17110310/how-can-i-reduce-the-linear-fit-plot-to-a-certain-interval?rq=1) is misleading? – Golam May 09 '14 at 12:03
  • Yes, that answer is wrong, don't know why it was marked as accepted. The syntax show there works only in the development version (upcoming version 5.0). I'll leave a comment. – Christoph May 09 '14 at 14:01