matplotlib backends – do I care?

Question:

>>> import matplotlib
>>> print matplotlib.rcsetup.all_backends
[u'GTK', u'GTKAgg', u'GTKCairo', u'MacOSX', u'Qt4Agg', u'Qt5Agg', u'TkAgg', u'WX', u'WXAgg', u'CocoaAgg', u'GTK3Cairo', u'GTK3Agg', u'WebAgg', u'nbAgg', u'agg', u'cairo', u'emf', u'gdk', u'pdf', u'pgf', u'ps', u'svg', u'template']

Look at all those backends!

Do I need to care which backend is in use? e.g. if I develop and test my stuff using only TkAgg backend, and someone else using my code might be using GTKAgg backend on their system, might my stuff break for them in a way that I won’t have noticed – or are all backends required to more or less “work” the same way?

Asked By: wim

||

Answers:

The backend mainly matters if you’re embedding matplotlib in an application, in which case you need to use a backend (GTK, Qt, TkInter, WxWindows) which matches the toolkit you’re using to build your application. If you’re also using matplotlib in a simple interactive way, you’ll also want to use a backend which matches what is available on your machine (GTK if you’re running Gnome, Qt if you’re running KDE, etc) (although most libs are already installed on most machines)

The drawing layer part of the backend (Cairo, Agg…) also matters in terms of functionalities: you can choose it depending on what that layer provides compared to what your application needs (anti aliasing, alpha channel, export formats…). So if you develop and test using TkAgg and other people run with e.g. TkCairo, some things might not work. OTOH, running with QtAgg would certainly work in a very similar way as long as you stick to the matplotlib API and don’t reach in the wrapped toolkit layer.

Answered By: gurney alex
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.