[Matplotlib-devel] Response to architecture query

Benjamin Root ben.v.root at gmail.com
Tue Feb 9 11:52:47 EST 2016


Excerpt response to a private query about matplotlib's architecture. Some
has asked me to post it as a possible addition to development docs.


All of matplotlib started off as pure python. As time went on, it was
re-worked into a backend/frontend design. The frontend is mostly in python,
with critical portions, such as path and vector handling implemented in
C++. We are also heavily reliant upon NumPy and use its C-API in those C++
parts. We also call out to various other libraries such as libfreetype to
perform our font-handling. The frontend is also a bit of a misnomer,
because it isn't really at the front, as most people are familiar with the
pyplot interface, which sits on top of the frontend.

The backends are what allows us to output the figures to the many different
"devices" (filetypes, GUI toolkits, etc.). Most are implemented in python
using the respective GUI toolkit's python bindings. The Tk backend, oddly
enough, is implemented in C/C++ (don't ask me why, I haven't a clue), and
the macosx backend is implemented in Obj-C. The AGG backend is implemented
in C++. PDF and PS backends are implemented in python as well.

AGG is critically important to matplotlib's functionality. Not only does it
serve as the default headless backend, and is often mixed with the GUI
backends (TkAgg, Qt4Agg, etc.) to produce consistent results across all
platforms, it also serves as the basis for our image-handling architecture.

This is a very broad-brush overview of the matplotlib architecture. It
isn't a simple layered system, unfortunately, but we do have some critical
portions off-loaded to C/C++ or NumPy. Probably some of the most
difficult-to-understand portions of the codebase isn't those parts, though.
It is the figure/axes/axis relationships for defining properties at the
right time (lots of multiple-inheritance confusion) as well as the
figure/canvas/manager relationships for interactivity.


Cheers!
Ben Root
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-devel/attachments/20160209/9cd95dfd/attachment.html>


More information about the Matplotlib-devel mailing list