Setting up Octave and Gnuplot on Apple Mac OSX

I just started auditing a Mathematical Models in Biology class and Matlab is one of the requirements. I had relatively good experience with the free, open source alternative,Octave back in college, but then I was running Linux, not OSX. It took me about an hour to figure out how to set it up (I was a little worried for a bit).

  1. Download the Octave binary for OSX from Octaveforge.
  2. Install Octave and Gnuplot (in the extras folder). I just dragged them to /Applications (X11 is required for Gnuplot—should be found on OSX install disk)
  3. If you are using OSX 10.6 (Snow Leopard) or 10.5.8+ you may need to perform some additional steps outlined here
  4. Set the environment variable for gnuplot (Octave is supposed to do this automatically, but it didn’t for me):
    sudo ln -s /Applications/GnuPlot.app/Contents/Resources/bin/gnuplot /usr/bin/gnuplot

    (thanks for the help, Toby)
  5. Download and install (again in /Applications) Aquaterm which will actually render the gnuplot graphs.
  6. Within Gnuplot, set the renderer: “terminal aqua”
  7. Try it out in Octave (I had to restart Octave and Gnuplot to get it all to work):
    x = linspace(-pi, pi, 100);
    y = sin(x);
    plot(x, y);

Thank you: High Performance Computing for Mac OS X, the Octave Wiki and Google for helping me find what I needed.

Update (January 24, 2010): updated the link in step #1 to the latest version of Octave. Added an additional step described by Zack in the comments (thanks!)

29 comments

Rick #permalink

I’m having the same problem as joaquin.… Please Help!!

Thank you!

Daniel Stegmueller #permalink

Well, that was really helpful.
I was searching for a gnuplot binary and hadn’t realized that octave provided one…

Thanks a lot!

Best,
Daniel

Toby #permalink

Hi, thanks that’s a good explanation. I tried it but it only works when I log in as administrator. Typically I use a standard user account, and then I always get the error message “unable to open display ‘:0.0′ X11 aborted”. On the other hand, if I start X11 first, then plotting works, however, plots are shown directly in X11, not with AquaTerm. Do you have an idea what might be wrong and how it could be fixed?

Toby #permalink

Re: AquaTerm problem
Actually, gnuplot works fine with AquaTerm, the problem must be that octave doesn’t talk to gnuplot. For setting up the symbolic link I had to switch user accounts. It would only work from the admin account, and only with ‘sudo’. Did you not have to do that?

Toby #permalink

PS: Octave
Hi again, just wanted to let everybody know, that it must be a problem with my current user account. I finally remembered the typical test, i.e., create a clean new user account and see if that works. And it does. In other words, one does not have to be administrator. However, as mentioned above, to create the symbolic link mentioned in the post, the following command has to be entered from an admin account: “sudo ln –s /Applications/GnuPlot.app/Contents/Resources/bin/gnuplot /usr/bin/gnuplot”.

Thanks,
Toby

ben #permalink

Awesome, thanks for the feedback. I’ll update the script—you were right.

joaquin #permalink

hi, I installed octave and gnuplot, and when I tried to plot sin(x), octave shows me the following error:

octave-3.0.1:2> plot(x,sin(x))
dyld: Library not loaded: /usr/X11R6/lib/libXpm.4.dylib
Referenced from: /Applications/Gnuplot.app/Contents/Resources/bin/gnuplot-4.2.3
Reason: image not found
dyld: Library not loaded: /usr/X11R6/lib/libXpm.4.dylib
Referenced from: /Applications/Gnuplot.app/Contents/Resources/bin/gnuplot-4.2.3
Reason: image not found
/Applications/Gnuplot.app/Contents/Resources/bin/gnuplot: line 75: 3092 Trace/BPT trap GNUTERM=”${GNUTERM}” GNUPLOT_HOME=”${GNUPLOT_HOME}” PATH=”${PATH}” DYLD_LIBRARY_PATH=”${DYLD_LIBRARY_PATH}” HOME=”${HOME}” GNUHELP=”${GNUHELP}” DYLD_FRAMEWORK_PATH=”${DYLD_FRAMEWORK_PATH}” GNUPLOT_PS_DIR=”${GNUPLOT_PS_DIR}” DISPLAY=”${DISPLAY}” GNUPLOT_DRIVER_DIR=”${GNUPLOT_DRIVER_DIR}” “${ROOT}/bin/gnuplot-4.2.3″ “$@“
/Applications/Gnuplot.app/Contents/Resources/bin/gnuplot: line 75: 3098 Trace/BPT trap GNUTERM=”${GNUTERM}” GNUPLOT_HOME=”${GNUPLOT_HOME}” PATH=”${PATH}” DYLD_LIBRARY_PATH=”${DYLD_LIBRARY_PATH}” HOME=”${HOME}” GNUHELP=”${GNUHELP}” DYLD_FRAMEWORK_PATH=”${DYLD_FRAMEWORK_PATH}” GNUPLOT_PS_DIR=”${GNUPLOT_PS_DIR}” DISPLAY=”${DISPLAY}” GNUPLOT_DRIVER_DIR=”${GNUPLOT_DRIVER_DIR}” “${ROOT}/bin/gnuplot-4.2.3″ “$@“
error: you must have gnuplot installed to display graphics; if you have gnuplot installed in a non-standard location, see the ‘gnuplot_binary’ function

and I really don‘t know what to do

joaquin #permalink

If, someone could help me, I would be very gratefull!

thanks

Juan #permalink

Joaquin,

You are getting this error because you dont have installed (somehow) the X11 environment.
I was having the same problem than you and now it is working without any problem.
You can install it from the Tiger or Leopard DVD or you can surf the web looking for it.

Best,

Juan

regula #permalink

Thank You!!
This just safed my day (if not the whole semester or even more :) — beautiful!
Aquaterm was missing (why won’t anyone tell one this) and now all is well.

Maxwell Grady #permalink

Thank you so much for this; this totally saved me a lot of time.

Once I found a download link for the correct version of X11 to install on my macbook I just followed your instructions plain and simple and it worked perfect.

Thanks a million.

Optimality! » Setting up Octave and Gnuplot on OSX #permalink

[…] Good instructions are here. […]

Mareo Raft #permalink

thank you thank you thank you!!!!

Brian Van Straalen #permalink

another approach instead of the sudo ln command.

install all three packages mentioned: AquaTerm, GNUPlot, Octave.

then add to your .bashrc file

PATH=/Applications/octave.app/Contents/Resources/bin:/Applications/Gnuplot.app/Contents/Resources/bin:$PATH

this seems to work for me.

Arnau #permalink

Hey guys,

first of all thank you for the information.

Actually, I have the same problem than Joaquin. I’m not english good speaker, I’m only an student. I tried to fix it up but I can’t. Somebody said that the problem is in X11. But I have it installed and I tried to run it before trying to plot in Octave.. I’m kind of lost and I need to fix it. THANK’S!!

Zach #permalink

Joaquin and everyone who had the same problem, this fixed it for me:

http://sourceforge.net/projects/octave/files//Octave%20MacOSX%20Binary/2009–10-03%20binary%20of%20Octave%203.2.3/README_OSX1065.txt/view

Leslie #permalink

Hi!
Thanks for the detailed instructions! They were really, really helpful.
I was having the so said problem with the plot(x) command, too; but now it seems to be working just fine (I was actually missing the additional steps on #3).

Martin #permalink

Thanks for this, I’m a complete n00b to macs and found this easy to do!

Tysen #permalink

Thanks for the instructions.

Strange Loops – P. Syriac #permalink

[…] getting Octave/GNUPlot to work on MacOSX wasn’t as straightforward as I’d have […]

netpublicus #permalink

Hello together,
thank you for your great guide. There is still a catch I can’t figure out. Please help me.

AIM: Plotting functions in Latex
Ressources: Mac Snow (10.6.8.), X11, Latex, gnu plotter, Octavia, Aquaterm,

I followed all steps in the guide and the comments.
However I get these errors: (see below)

Thank for help!!!

When running gnu plotter I get this error:

~ netpublicus$ exec ‘/Applications/Gnuplot.app/Contents/Resources/bin/gnuplot’
dyld: Library not loaded: /usr/X11R6/lib/libXpm.4.dylib
Referenced from: /Applications/Gnuplot.app/Contents/Resources/bin/gnuplot-4.2.6
Reason: image not found
/Applications/Gnuplot.app/Contents/Resources/bin/gnuplot: line 71: 685 Trace/BPT trap GNUTERM=”${GNUTERM}” GNUPLOT_HOME=”${GNUPLOT_HOME}” PATH=”${PATH}” DYLD_LIBRARY_PATH=”${DYLD_LIBRARY_PATH}” HOME=”${HOME}” GNUHELP=”${GNUHELP}” DYLD_FRAMEWORK_PATH=”${DYLD_FRAMEWORK_PATH}” GNUPLOT_PS_DIR=”${GNUPLOT_PS_DIR}” DISPLAY=”${DISPLAY}” GNUPLOT_DRIVER_DIR=”${GNUPLOT_DRIVER_DIR}” “${ROOT}/bin/gnuplot-4.2.6″ “$@”

[Prozess beendet]

and from OCTAVIA:

octave-3.2.3:1> plot x*2
error: plot: no data to plot
error: called from:
error: /Applications/Octave.app/Contents/Resources/share/octave/3.2.3/m/plot/__plt__.m at line 90, column 4
error: /Applications/Octave.app/Contents/Resources/share/octave/3.2.3/m/plot/plot.m at line 186, column 5
dyld: Library not loaded: /usr/X11R6/lib/libXpm.4.dylib
Referenced from: /Applications/Gnuplot.app/Contents/Resources/bin/gnuplot-4.2.6
Reason: image not found
dyld: Library not loaded: /usr/X11R6/lib/libXpm.4.dylib
Referenced from: /Applications/Gnuplot.app/Contents/Resources/bin/gnuplot-4.2.6
Reason: image not found
/Applications/Gnuplot.app/Contents/Resources/bin/gnuplot: line 71: 755 Trace/BPT trap GNUTERM=”${GNUTERM}” GNUPLOT_HOME=”${GNUPLOT_HOME}” PATH=”${PATH}” DYLD_LIBRARY_PATH=”${DYLD_LIBRARY_PATH}” HOME=”${HOME}” GNUHELP=”${GNUHELP}” DYLD_FRAMEWORK_PATH=”${DYLD_FRAMEWORK_PATH}” GNUPLOT_PS_DIR=”${GNUPLOT_PS_DIR}” DISPLAY=”${DISPLAY}” GNUPLOT_DRIVER_DIR=”${GNUPLOT_DRIVER_DIR}” “${ROOT}/bin/gnuplot-4.2.6″ “$@“
error: you must have gnuplot installed to display graphics; if you have gnuplot installed in a non-standard location, see the ‘gnuplot_binary’ function
/Applications/Gnuplot.app/Contents/Resources/bin/gnuplot: line 71: 749 Trace/BPT trap GNUTERM=”${GNUTERM}” GNUPLOT_HOME=”${GNUPLOT_HOME}” PATH=”${PATH}” DYLD_LIBRARY_PATH=”${DYLD_LIBRARY_PATH}” HOME=”${HOME}” GNUHELP=”${GNUHELP}” DYLD_FRAMEWORK_PATH=”${DYLD_FRAMEWORK_PATH}” GNUPLOT_PS_DIR=”${GNUPLOT_PS_DIR}” DISPLAY=”${DISPLAY}” GNUPLOT_DRIVER_DIR=”${GNUPLOT_DRIVER_DIR}” “${ROOT}/bin/gnuplot-4.2.6″ “$@“
octave-3.2.3:1>

Michael #permalink

Thanks for writing these notes. I just installed octave on my Mac 10.6.8 machine and was having trouble getting plots to work. Steps 3 and 4 were the keys to making it work for me. Thanks again!

Amy #permalink

Thank you so much for the concise explanation!!! It saved me many hours of stress!!!

Adria #permalink

Hello,

I have installed Gnuplot, X11, Octave and Aquaterm, but I have a problem:

- When I use the plot command in octave, Aquaterm opens but doesn’t show anything.

Does anybody know how to solve this problem?

Thanks

GTS #permalink

I’m having the same problem as Adria. Has anyone figured it out?

Thanks

GTS #permalink

This fixed my problem (from the octave 3.4.0 readme.html file):

On a very small number of Mac systems an AquaTerm window is not opened at all. Therefore AquaTerm.app has been included into Gnuplot.app and that can be started automatically if Gnuplot.app’s startup script /Contents/Resources/bin/gnuplot is modified. Change the lines

# DYLD_FRAMEWORK_PATH=”${ROOT}/lib:${DYLD_FRAMEWORK_PATH}” \
# open “${ROOT}/lib/AquaTerm.app“
into

DYLD_FRAMEWORK_PATH=”${ROOT}/lib:${DYLD_FRAMEWORK_PATH}” \
open “${ROOT}/lib/AquaTerm.app“
which will open AquaTerm.app automatically if you launch Gnuplot.app.

Hardik #permalink

Awesome thanks !! I just did what was in step 3 as I was on Snow Leopard and success!!! Highly recoemmend all those on Snow Leopard and having issues to try this first. The other step mentioned here gave me error so not sure about the sudo command etc…

http://sourceforge.net/projects/octave/files//Octave%20MacOSX%20Binary/2009–10-03%20binary%20of%20Octave%203.2.3/README_OSX1065.txt/view

elzinko #permalink

thank you GTS for sharing your trick since it solved the problem that you described

sh #permalink

Bless you for this. I’m running 10.5.8 (99.99% of the time I wouldn’t care about upgrading) and eventually was able to get Octave 3.2.2 and Gnuplot/Aquaterm working with this and the comments above. I could probably get 3.4 to go but as this is just a short-term thing for me anyway I won’t risk fubaring up something that works.

Leave your comment