本文摘译了《Matplotlib手册》(Matplotlib_3.2.1.pdf) 中关于 Matplotlib 的若干概念。
◆ 正文
Matplotlib graphs your data on Figures, each of which can contain one or more Axes (i.e., an area where points can be specified in terms of x-y coordinates (or theta-r in a polar plot, or x-y-z in a 3D plot, etc.).
Matplotlib 将数据绘制在 Figure 上。每个 Figure 能包括一个或多个 Axes(坐标系)。每个 Axes 中的点能用 x-y 坐标格式指定(或在极坐标系中用 theta-r 格式,在 3D 坐标系中用 x-y-z 格式)。
use Axes.plot to draw some data on the axes.
使用 Axes.plot 在坐标系中描绘数据。
for each Axes graphing method, there is a corre- sponding function in the matplotlib.pyplot module that performs that plot on the ”current” axes, creating that axes (and its parent figure) if they don’t exist yet.
对于每个 Axes 的绘图方法,在 matplotlib.pyplot 模块中都有一个对应的函数。该模块在“当前”坐标系上绘图,如果坐标系不存在,则会创建该 Axes(以及它的所属 Figure)。
The figure keeps track of all the child Axes, a smattering of ’special’ artists (titles, figure legends, etc), and the canvas. (Don’t worry too much about the canvas, it is crucial as it is the object that actually does the drawing to get you your plot, but as the user it is more-or-less invisible to you). A figure can contain any number of Axes, but will typically have at least one.
Figure 跟踪所有从属的 Axes、少量“特殊的”绘图内容(标题、图例等)和 canvas(虽然 canvas 是实际上绘图的位置,但也不必过于担心它,因为它或多或少不可见)。一个 Figure 能包含任意多个 Axes,但至少会有一个。
Axes This is what you think of as ’a plot’, it is the region of the image with the data space. A given figure can contain many Axes, but a given Axes object can only be in one Figure. The Axes contains two (or three in the case of 3D) Axis objects (be aware of the difference between Axes and Axis) which take care of the data limits. Each Axes has a title, an x-label, and a y-label. The Axes class and its member functions are the primary entry point to working with the OO interface.
Axes 是被人们认为的绘图区,它是带有数据空间的图像区域。一个 Figure 能包含许多 Axes,但一个 Axes 只能在一个 Figure 中。Axes 包括两个 Axis 对象(在 3D 坐标系中是三个,要注意 Axes 和 Axis 的不同)。每个 Axis 对象关注数据边界。每个 Axes 有一个标题、一个 x 轴标签 和一个 y 轴标签。Axes 类和它的成员函数是使用 OO 接口的主要入口。
Axis These are the number-line-like objects. They take care of setting the graph limits and generating the ticks (the marks on the axis) and ticklabels (strings labeling the ticks). The location of the ticks is determined by a Locator object and the ticklabel strings are formatted by a Formatter. The combination of the correct Locator and Formatter gives very fine control over the tick locations and labels.
Axis 是类似数据线的对象。它们关注绘图边界以及生成 tick(在 Axis 上的标记)和 ticklabel(标记 tick 的字符串)。tick 的位置由 Locator 对象决定,ticklabel 字符串由 Formatter 格式化。正确的 Locator 和 Formatter 组合可以很好地控制 tick 的位置和标签。
Artist Basically everything you can see on the figure is an artist (even the Figure, Axes, and Axis objects). This includes Text objects, Line2D objects, collections objects, Patch objects ... (you get the idea). When the figure is rendered, all of the artists are drawn to the canvas. Most Artists are tied to an Axes; such an Artist cannot be shared by multiple Axes, or moved from one to another.
Artist 基本上是能在 Figure 上看到的每个东西(甚至是 Figure,Axes 和 Axis 对象)。这些对象包括 Text、Line2D、Collections、Patch 等你能想象到的所有对象。当 Figure 被描绘出来时,所有 Artist 被画在 canvas 上。大部分的 Artist 与 Axes 关联;一个 Artist 不能在多个 Axes 间共享,或从一个 Axes 移动到另一个。
All of plotting functions expect numpy.array or numpy.ma.masked_array as input.
所有绘图函数都期望 numpy.array 或 numpy.ma.masked_array 作为输入。
Explicitly create figures and axes, and call methods on them (the ”object-oriented (OO) style”). Rely on pyplot to automatically create and manage the figures and axes, and use pyplot functions for plotting. In general, we suggest to restrict pyplot to interactive plotting, and to prefer the OO-style for non-interactive plotting (in functions and scripts that are intended to be reused as part of a larger project).
显式地创建 Figure 和 Axe,并调用它们的方法(OO 风格)。依赖于 pyplot 自动创建和管理 Figure 和 Axe,并使用 pyplot 函数进行绘图(pyplot 风格)。总的来说,我们建议限制 pyplot 用于交互式绘图,优先使用 OO 风格用于非交互式绘图(写在要被重用的函数和脚本中,可以作为大项目的一部分)。
The recommended function signature is something like:
def my_plotter(ax, data1, data2, param_dict):
"""
A helper function to make a graph
Parameters
----------
ax : Axes
The axes to draw to
data1 : array
The x data
data2 : array
The y data
param_dict : dict
Dictionary of kwargs to pass to ax.plot
Returns
-------
out : list
list of artists added
"""
out = ax.plot(data1, data2, **param_dict)
return out
绘图工具函数的推荐函数签名如上。
matplotlib can target different outputs, and each of these capabilities is called a backend; the ”frontend” is the user facing code, i.e., the plotting code, whereas the ”backend” does all the hard work behind-the-scenes to make the figure. There are two types of backends: user interface backends (also referred to as ”interactive backends”) and hardcopy backends to make image files (also referred to as ”non-interactive backends”).
matplotlib 能处理不同的输出,每种不同的输出能力被称为一种 backend;frontend 指的是用户面对的代码,例如,绘图代码。然而,为了生成图像,backend 在幕后做着艰苦的工作。存在两种类型的 backend:用户接口 backend(也被称为交互式 backend)和用于生成图像文件的硬拷贝 backend(也称为非交互式 backend)。
matplotlib separates the concept of the renderer (the thing that actually does the drawing) from the canvas (the place where the drawing goes).
matplotlib 从 canvas (绘图的场所)中分离出了 renderer (实际做渲染工作的东西)的概念。(译注:canvas + renderer 的组合构成了一个 backend。)
For the rendering engines, one can also distinguish between vector or raster renderers. Vector graphics languages issue drawing commands like ”draw a line from this point to this point” and hence are scale free, and raster backends generate a pixel representation of the line whose accuracy depends on a DPI setting.
对于渲染引擎而言,能分为 vector 渲染器和 raster 渲染器。vector 渲染器提供了类似于“从这一点画到那一点”的绘图命令,因此它可以自由伸缩;而 raster 渲染器可以生成基于像素的线段,它的精确程度依赖于 DPI 设置。
non-interactive mode delays all drawing until show() is called
非交互式模式延迟所有的绘图任务直到 show() 被调用为止。
In interactive mode, pyplot functions automatically draw to the screen. When plotting interactively, if using object method calls in addition to pyplot functions, then call draw() whenever you want to refresh the plot. Use non-interactive mode in scripts in which you want to generate one or more figures and display them before ending or generating a new set of figures. In that case, use show() to display the figure(s) and to block execution until you have manually destroyed them.
在交互模式下,pyplot 函数自动地在屏幕上绘图。采用交互方式绘图时,如果调用的是对象方法,而不是pyplot 函数,则在刷新绘图区时需要调用 draw()。 在脚本结束绘图或生成一批图像前,如果想生成一个或多个图像,则需要使用非交互模式。在此情况下,使用 show() 来显示图像,可以终止程序执行直到手动销毁图像。
标签:plot,Figure,pyplot,Axes,Matplotlib,概念,绘图,Axis,若干 From: https://www.cnblogs.com/green-cnblogs/p/17787930.html