Baptiste Fontaine’s Blog  (back to the website)

Fixing gnuplot-py’s “unknown aqua terminal” warning on OSX

When plotting with gnuplot-py on OSX, I got an annoying warning saying that terminal aqua is unknown or ambiguous, even when I use a different terminal (e.g. postscript). This terminal doesn’t exist on my Gnuplot installation (4.6.3). In fact, gnuplot-py uses slightly different files depending on your platform. OSX’s one is exactly the same as other UNIX-flavored OSes but its default terminal is aqua. There are two ways to fix the warning, a hacky one I used before this blog post, and a clean one I discovered while writting this post. Hope this help!

The hacky way

Since OSX’s Gnuplot file is the same as Linux’s one apart from its default term, we just need to tell gnuplot-py we’re on Linux:

import sys
_platform = sys.platform # save the normal sys.platform value

if _platform == 'darwin':
    sys.platform = 'linux' # replace it with 'linux'

import Gnuplot, Gnuplot.funcutils # import Gnuplot
sys.platform = _platform # restore it

It temporarily changes sys.platform value, which gnuplot-py is relying on, to "linux", import Gnuplot and then restore it back to its previous value ("darwin").

The clean way

In fact there’s a much cleaner way to fix the warning. The default terminal is stored in GnuplotOpts.default_term, so we just need to change it to another value to fix the warning:

import Gnuplot, Gnuplot.funcutils
Gnuplot.GnuplotOpts.default_term = 'x11'

It’s cleaner than the hacky way because:

  1. It’s clear: the second line is pretty explicit: we change default_term to 'x11'. We don’t even need to add a comment.
  2. It’s more maintainable: if OSX’s gnuplot-py interface change in the future, this piece of code won’t break compatibility while the hacky way will prevent our code to use the new interface.
  3. It’s shorter: one line versus five ones. It’s really easier to introduce bugs when using five lines instead of just one.