Nice Octave Plots

One thing I look for in a numerical package is the ability to make nice plots (typically PDF) of what I’m working on. I know I could almost always work on my data, export it, and make a great graph… but in keeping with the 80/20 rule I want to be able to do most of my plots without a lot of extra work. This is especially true if I’m making a one-off plot for class notes. For publications, I’d be happy to hand draw the figure in blood while standing on my head if I had to. The bottom line is: it’s 2009, making a nice looking PDF plot should be easy.

Here is an example along with some quick tips I’ve found along the way. Hopefully these are easier to find for you than they were for me (digging through docs and searching through listservs). Remember, Octave is scriptable so you can save this in a plot template or a function, and make your plots even easier.

Nice EPS output:

h = figure;
set (h,'papertype', '<custom>')
set (h,'paperunits','inches');
set (h,'papersize',[3 2.5])
set (h,'paperposition', [0,0,[3 2.5]])
set (h,'defaultaxesposition', [0.15, 0.15, 0.75, 0.75])
set (0,'defaultaxesfontsize', 14)
xlabel('Time (s)')
ylabel('Velocity (m/s)')

The commands here select the papertype (as custom) and use inch units (could be ‘centimeters’ too). Next, set the paper size (figure size) and the position on the paper. The coordinates for paper position are [left bottom width height]. The default axes position is similar, although now in normalized units (between 0 and 1). I like the look of these axes, and there isn’t too much whitespace. I also like a clear legible font size (14 in this example). The rest are some axes labels.

Nice PDF plots

PDF plots are still problematic because it seems like I have to run an extra step. Either I can convert the EPS to PDF, or I can export PDF and then crop the PDF so the whole page isn’t showing. For the former option, I just open the EPS in and save as a PDF (this gives me the intermediate preview step for free). For the latter option, I have found pdfcrop useful. This is a little utility that ships wih TeX-Live which I have installed as part of MacTex 2008. There is a newer version MacTex 2009. In any case, the only major difference is the final print command:


If you have a more elegant solution, please let me know. I think better PDF exports are on the list for Octave development but the current priority (in terms of graphics output) seems to be breaking away from Gnuplot and allowing other graphics backends. In general, this is a good thing. I love Gnuplot, but there are certainly uses where Gnuplot isn’t the best tool in the toolbox.

Endnote: I’m using Octave 3.2.2 and Gnuplot 4.2 patchlevel 5 on a PPC mac. These packages were downloaded from Octave Forge.

4 thoughts on “Nice Octave Plots

  1. This was a great tip; thanks! I didn’t know about papertype and papersize. Just FYI, new versions of Preview have a crop tool. Select the part of the image that you want and hit command-K. I personally (and weirdly) still bring my exported EPS files into Illustrator and fix them up. There are still so many subtle things that automated visualizers still can’t capture.

  2. Have a look at svg-export and the current inkscape-development-branch (bazaar).

    inkscape can import the svg, and export it as pdf+tex, which can be included directly into your tex-document. now, the text is rendered by tex itself, which correct font, scaling, tex-syntax and all… work very good for me

  3. Pingback: save plot of customised font setting to file in Octave | 一沙一世界,一花一天堂

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s