首页 > 其他分享 >Matplotlib的若干概念

Matplotlib的若干概念

时间:2023-10-25 19:24:12浏览次数:31  
标签:plot Figure pyplot Axes Matplotlib 概念 绘图 Axis 若干

本文摘译了《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)。

anatomy_of_a_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

相关文章

  • 数据统计分析 — 统计学的几个概念
    变量分类变量无序分类变量说明事物类别的一个名称,如:性别有男女两种,二者无大小之分,无顺序之分,还有如血型、民族等有序分类变量也是说明事物类型的一个名称,但是有次序之分,例如:满意度分为满意一般不满意,三者是有顺序的,但是无大小之分数值型变量连续型变量取值范围是......
  • NeurIPS 2023 | 「解释一切」图像概念解释器来了,港科大团队出品
    前言 SegmentAnythingModel(SAM)首次被应用到了基于增强概念的可解释AI上。本文转载自机器之心仅用于学术分享,若侵权请联系删除欢迎关注公众号CV技术指南,专注于计算机视觉的技术总结、最新技术跟踪、经典论文解读、CV招聘信息。CV各大方向专栏与各个部署框架最全教程整理......
  • 【matplotlib 实战】--热力图
    热力图,是一种通过对色块着色来显示数据的统计图表。它通过使用颜色编码来表示数据的值,并在二维平面上呈现出来。热力图通常用于显示大量数据点的密度、热点区域和趋势。绘图时,一般较大的值由较深的颜色表示,较小的值由较浅的颜色表示;较大的值由偏暖的颜色表示,较小的值由较冷的颜色......
  • Python 利用pandas 和 matplotlib绘制柱状图
    当你需要展示数据时,图表是一个非常有用的工具。Python中的pandas和matplotlib库提供了丰富的功能,可以帮助你轻松地绘制各种类型的图表。本文将介绍如何使用这两个库,绘制一个店铺销售数量的柱状图,并添加各种元素,如数据标签、图例、网格线等。准备工作在开始之前,你需要安装p......
  • IO流,对象流,基本概念
    序列化:对象转换为字节序列的过程称为对象的序列化。把字节序列恢复为java对象的过程称为对象的反序列化。序列化的作用两种:1、持久化:把对象的字节序列永久保存在硬盘中。2、网络通信:在网络上传送对象的字节序列。如:服务器之间的数据通信、对象传递 ObjectOutputStream代表对......
  • 吊打收费好用到爆系列软件:免费绘画软件 草图概念图 动画 漫画 插画、接景甚至 3D 贴图
    吊打收费好用到爆系列软件:免费绘画软件草图概念图动画漫画插画、接景甚至3D贴图防抖、数位板、色彩管理、滤镜压感图层官方承诺绝无功能限制或商业限制,可以自由免费使用!请点击文后【阅读原文】查看更多优爱酷优爱酷,专注研究AI技术、专心探索软件奥秘、专业研发......
  • matplotlib.pyplot入门
    matplotlib.pyplot入门引言matplotlib是一个功能强大的Python绘图库,通过它可以用于生成各种类型的高质量图表和可视化效果。其中,pyplot是matplotlib库中的一个子模块,用于创建各种类型的图表,并提供了丰富的绘图函数和方法。本文将引导您快速入门使用matplotlib.pyplot来创建简单的图......
  • 【matplotlib 实战】--漏斗图
    漏斗图,形如“漏斗”,用于展示数据的逐渐减少或过滤过程。它的起始总是最大,并在各个环节依次减少,每个环节用一个梯形来表示,整体形如漏斗。一般来说,所有梯形的高度应是一致的,这会有助人们辨别数值间的差异。需要注意的是,漏斗图的各个环节,有逻辑上的顺序关系。同时,漏斗图的所有环节的......
  • 阅读笔记 1: 重构的基本概念
    第一章引言部分强调了重构的重要性和它在软件开发中的角色。作者马丁·福勒首先介绍了代码坏味道(codesmells)的概念,这些是代码中的不良迹象,可能导致未来的问题。作者指出,即使代码能正常运行,但它仍然可能有坏味道,这是因为代码的结构不佳、可读性差或难以维护。这是一个非常关键的洞......
  • 模拟集成电路设计系列博客——3.3.1 带隙电压基准概念
    3.3.1带隙电压基准概念在模拟电路模块,尤其是数据转换模块中,一个非常重要的组件是电压参考。理想情况下,这个模块输出一个固定的已知幅度的直流电压,并且不随温度发生变化。通过这个模块再结合一个精确的电阻可以提供一个稳定的直流电流。有一系列手段可以产生集成电路中的电压参考......