Skip to content

Commit 3bf537b

Browse files
committed
WIP
1 parent 94f05aa commit 3bf537b

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

doc/users/explain/architecture.rst

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,83 @@ Matplotlib architecture
66

77
.. _article: https://www.aosabook.org/en/matplotlib.html
88
.. _blog: https://medium.datadriveninvestor.com/data-visualization-with-python-matplotlib-architecture-6b05af533569
9+
.. _she06: Maxim Shemanarev. Anti-Grain Geometry: A high quality rendering engine for C++, 2002-2006.
10+
11+
Overview of matplotlib Architecture
12+
-----------------------------------
13+
14+
The top-level matplotlib object that contains and manages all of the elements in
15+
a given graphic is called the Figure.
16+
17+
From :ref:`figure_parts`:
18+
19+
* :class:`~matplotlib.figure.Figure`
20+
The **whole** figure. The Figure keeps track of all the child
21+
:class:`~matplotlib.axes.Axes`, a group of 'special' Artists (titles, figure
22+
legends, colorbars, etc), and even nested subfigures.
23+
24+
One of the core architectural tasks matplotlib must solve is implementing a
25+
framework for representing and manipulating the ``Figure`` that is segregated
26+
from the act of rendering the ``Figure`` to a user interface window or hardcopy.
27+
This enables us to build increasingly sophisticated features and logic into the
28+
``Figures``, while keeping the "backends", or output devices, relatively simple.
29+
matplotlib encapsulates not just the drawing interfaces to allow rendering to
30+
multiple devices, but also the basic event handling and windowing of most
31+
popular user interface toolkits. Because of this, users can create fairly rich
32+
interactive graphics and toolkits incorporating mouse and keyboard input that
33+
can be plugged without modification into the six user interface toolkits we
34+
support. [1]
35+
36+
The architecture to accomplish this is logically separated into three layers,
37+
which can be viewed as a stack. Each layer that sits above another layer knows
38+
how to talk to the layer below it, but the lower layer is not aware of the
39+
layers above it. The three layers from bottom to top are: *backend*, *artist*,
40+
and *scripting*. [1]
41+
42+
Backend Layer
43+
~~~~~~~~~~~~~
44+
45+
At the bottom of the stack is the backend layer, which provides concrete
46+
implementations of the abstract interface classes:
47+
48+
* ``FigureCanvas`` encapsulates the concept of a surface to draw onto (e.g. "the
49+
paper").
50+
* ``Renderer`` does the drawing (e.g. "the paintbrush").
51+
* ``Event`` handles user inputs such as keyboard and mouse events.
52+
53+
The abstract base class ``FigureCanvas`` has concrete implementations for all
54+
user interface toolkits, such as Qt and GTK. The abstract base classes reside in
55+
`matplotlib.backend_bases` and all of the derived classes live in dedicated
56+
modules like `matplotlib.backends.backend_qt4agg`.
57+
58+
The job of the ``Renderer`` is to provide a low-level drawing interface for
59+
putting ink onto the canvas. One of the design decisions that has worked quite
60+
well for matplotlib is support for a core pixel-based renderer using the C++
61+
template library *Anti-Grain Geometry* or "agg" [She06]. This is a
62+
high-performance library for rendering anti-aliased 2D graphics that produces
63+
attractive images. matplotlib provides support for inserting pixel buffers
64+
rendered by the agg backend into each user interface toolkit we support, so one
65+
can get pixel-exact graphics across UIs and operating systems. Because the PNG
66+
output matplotlib produces also uses the agg renderer, the hardcopy is identical
67+
to the screen display, so what you see is what you get across UIs, operating
68+
systems and PNG output.
69+
70+
The matplotlib ``Event`` framework maps underlying UI events like
71+
``key-press-event`` or ``mouse-motion-event`` to the matplotlib classes
72+
``KeyEvent`` or ``MouseEvent``. Users can connect to these events to callback
73+
functions and interact with their figure and data; for example, to pick a data
74+
point or group of points, or manipulate some aspect of the figure or its
75+
constituents.
76+
77+
Artist layer
78+
~~~~~~~~~~~~
79+
80+
The ``Artist`` is the object that knows how to take the ``Renderer`` (the
81+
paintbrush) and put ink on the canvas. Everything you see in a matplotlib
82+
``Figure`` is an ``Artist`` instance; the title, the lines, the tick labels, the
83+
images, and so on all correspond to individual ``Artist`` instances. The base
84+
class is ``matplotlib.artist.Artist``, which contains attributes that every
85+
``Artist`` shares.
86+
87+
There is a hierarchy between artists in the same ``Figure``.
88+

0 commit comments

Comments
 (0)