Question

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

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top