Less is more effective
Less is more attractive
Less is more impactive
Matplotlib architecture
Matplotlib体系结构分为三层,可以将其视为堆栈。位于另一层之上的每一层都知道如何与它下面的层进行通信,但是下层却不知道它上面的层。从下到上的三层是:Backend, Artist, Scripting Layer.
Backend Layer (FigureCanvas, Renderer, Event)
Has three built-in abstract interface classes:
- FigureCanvas: matplotlib.backened_bases.FigureCnvas
- Encompasses the area onto which the figure is drawn
- 例如画纸
- Renderer: matplotlib.backened_bases.Renderer
- Knows how to draw on the FigureCanvas
- 例如画笔
- Knows how to draw on the FigureCanvas
- Event: matplotlib.backend_bases.Event
- Handles user inputs such as keyboard strokes and mouse clicks
Artist Layer (Artist)
- Comprised of one main object - Artist:
- Knows how to use the Renderer to draw on the canvas.
- 在matplotlib中看到的所有内容Figure都是一个 Artist实例。
- Title, lines, tick labels, and images, all correspond to individual Artist instances.
- Two types of Artist objects:
- Primitive: Line2D, Rectangle, Circle, and Text
- Composite: Axis, Tick, Axes, and Figure
- Each artist may contain other composite artists as well as primitive artists.
一个用Artist作图例子~
1 | # Putting the Artist Layer to Use |
Scripting Layer (pyplot)
- 日常用途,更简洁
- Comprised mainly of pyplot, a scripting interface that is lighter that the Artist layer.
- Let’s see how we can generate the same histogram of 10000 random values using the pyplot interface
1 | import matplotlib.pyplot as plt |