Plotting Graphs with Octave on Mac OS X

octaveDo you need to do math but can’t afford Matlab? Then GNU Octave may be right for you.

Octave is an open source computational package that is quite similar to Matlab in syntax. You can also use Octave to solve school math problems, create graphs and plots for reports, and much more.

If you are familiar with Matlab, using Octave will be smooth. With one big exception — plotting, if you are using OS X. In our experience, and many others if you search the web, plotting graphs using Octave can be troublesome on a Mac.

To check if everything works, start Octave in Terminal and type: sombrero(30)

If you see a bunch of error messages related to libfreetype and gnuplot, it may help to do the following.

First, stop running Octave. You can press CTRL+c to stop the sombrero plot, then write quit.

Restart Octave. At the prompt, before anything else, type: graphics_toolkit(‘fltk’).

Now try sombrero(30) again. Hopefully, you now see a nice sombrero function plotted in 3D (Figure 1).

If you want Octave plotting to function automatically at startup, which we think is a good idea, you can create a file in your home folder with the name .octaverc (Yes, it should start with a period. That is the way hidden files are denoted in OS X.).

Follow these steps to automate the plotting function:

1. Open a Terminal window by writing terminal in Spotlight. Spotlight is usually invoked by pressing COMMAND+spacebar (Spotlight is shown as the little blue search window in the top right corner of your screen. It’s also useful for finding other stuff on your computer).

2. In the new Terminal window, type: cd ~

3. Then type: nano .octaverc

4. If the .octaverc file already exists, you will see some text in the file already, otherwise it’s an empty file. Type: graphics_toolkit(‘fltk’);

5. Press: CTRL+o

6. Press: ENTER

7. Press: CTRL+x

Smile — you’re done. You can now restart Octave, and try the sombrero plot again. This time plotting should work right after start. Just type: sombrero(30), and on you go!