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:
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:
It’s cleaner than the hacky way because:
- It’s clear: the second line is pretty explicit: we change
default_term
to'x11'
. We don’t even need to add a comment. - 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. - It’s shorter: one line versus five ones. It’s really easier to introduce bugs when using five lines instead of just one.