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

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. Sorry to nag but, would this imply that this answer (stackoverflow.com/questions/17110310/…) is misleading?
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.