I've always considered gnuplot as very useful, and even more since I use tikz in LATEX documents. Unfortunately, the number of core implemented functions in gnuplot is quite small, I often need special functions like modified Bessel functions Kν and Iν. These functions cannot be written using the existing functions available in gnuplot. Is there a way to bind gnuplot and gsl libraries ? I've been browsing gnuplotting.org and other websites dedicated to gnuplot bu I found no word concerning this issue. If anyone has a clue, I would appreciate.

1 Answer 1


If you can write a command that can calculate the function you need, then you're done:

gnuplot> f(x) = real(system(sprintf("echo %f", x)))
gnuplot> plot f(x)

(see help system)

So you can use e.g. octave to calculate your value. E.g., if your system is linux, you can have directly:

gnuplot> bJ(a,x) = real(system(sprintf("echo 'besselj(%f,%f)' | octave | grep ^ans | cut -f 2 -d =", a,x)))
gnuplot> plot [0:20] bJ(1,x)

It will take some time to run, though! Set the sample value to something low until you've set every detail of your plot. If you need to replot many times, you can also tabulate your function first using set term table and then plot the tabulated values.

  • Many thanks. I didn't think of system. For functions I used quite often, it would be worth to compile a small binary interfacing a math library like the GSL to avoid the multiple conversions in the pipe chain you suggest.
    – Tom-Tom
    Feb 5, 2015 at 9:01
  • Sure, but in that case maybe it's worth having a binary that can tabulate the function rather than return a single value. In that case, you'll end up plotting a data file with modifiers rather than an analytical function with pointwise system-requests.
    – Joce
    Feb 5, 2015 at 14:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .