Matplotlib核心概念

作者: ACphart | 来源:发表于2018-08-04 09:56 被阅读11次

  • 摘抄自Duncan M. McGreggor所著《Mastering matplotlib》(Packt出版社)

Matplotlib架构

  • The current matplotlib architecture revolves around the operations that are necessary for the users to create, render, and update the Figure objects.
  • Figures can be displayed and interacted with via common user interface events such as the keyboard and mouse inputs. This layer of interaction with common user interface is called the backend layer.
  • A Figure needs to be composed of multiple objects that should be individually modifable, but it should be implemented in such a way that it has a positive and predictable impact on the other aspects of the Figure.
  • This logical layer is responsible for the abstraction of each visual component that one sees in a Figure. Due to its highly visual nature, this layer was identifed as the more general concept of creating visual art and is thus referred to as the artist layer.
  • Lastly, the Figure needs to support programmatic interaction and provide the users with the ability to manipulate Figures with a syntax that is as clean and intuitive as possible. This is called the scripting layer.

Backend Layer

  • the backends in matplotlib can be divided into two functional categories:
    User interface backends (interactive)
    Hardcopy backends (noninteractive)
  • Hardcopy backends can be further divided based on the support of raster graphics,vector graphics, or both of these.
  • Furthermore, the user-interface and hardcopy backends are built upon some core abstractions. The base classes for these are as follows:
    FigureCanvasBase and FigureManagerBase
    RendererBase and GraphicsContextBase
    Event, ShowBase, and Timer.
  • Examining these base classes brings us to the nuts and bolts of the matplotlib backend architecture.
如图:
FigureCanvasBase
  • The FigureCanvasBase class is a base class that is used by the user interface and hardcopy backends. It represents the canvas in which the Figure will render.Its responsibilities include the following:
    • Holding a reference to the Figure
    • Updating the Figure with a reference to the canvas
    • Defning event methods that run registered
    • Translating native toolkit events into the matplotlib event abstraction framework
    • Defning draw methods to render the Figure
    • Methods to start and stop non-GUI event loops
RendererBase
  • In matplotlib, the renderer handles the drawing operations.
Event
  • There are several aspects of the matplotlib backend that have to do with events,event loops, and timing. These responsibilities are divided across three base classes:
    Event: This is the base class for DrawEvent, MouseEvent, and KeyEvent, among others.
    ShowBase: This is subclassed at the module level in the GUI backends.
    TimerBase: This is the base class for TimerQT, TimerGTK3, and TimerWx, to name a few.

The artist layer

  • The artist layer constitutes the bulk of what matplotlib actually does—the generation of the plots for the purpose of display, manipulation, and publication. Most work in the artist layer is performed by a number of classes, most of which are derived from the Artist base class.
  • The artist layer is concerned with things such as the lines, shapes, axes, text, and so on.
  • The Artist subclasses can be classifed into one of the following two groups:
    Primitives
    Containers
Primitives
  • The matplotlib artist primitives are classes of graphical objects that are supposed to be painted on a fgure's canvas. These include, but are not limited to, the following:
    Line2D
    Shape (patch) classes such as Rectangle, Polygon, Ellipse, Circle, ArcText, Annotation, and TextPath
    AxesImage and FigureImage
  • Each of these primitive classes is a subclass of Artist, and as such have at their corethe same defnition of purpose—something that renders into an implementation of FigureCanvasBase.
Containers
  • This is another set of classes that subclass from Artist and which have additional responsibilities. They offer a useful abstraction to gather primitives. Examples of the containers include the following:
    Figure
    XAxis and YAxis
    Axes, PolarAxes, HammerAxes, MollweideAxes, and LambertAxes
    Subplot
  • Typically, a Figure would be instantiated and used to create one or more Axes or Subplot instances. The methods available for these objects would then be used to create the primitives as needed. Thus the user does not have to manually track the creation of the primitives and store them in the appropriate containers.
  • Of all the containers, the Axes class is one of the most important. It is the primary mover and shaker in the artist layer. The reason for this is simple—the Axes instances are where most of the matplotlib objects go (both primitives and other containers). In addition to the creation of primitives, the methods of this class can prepare the supplied data that is needed for the creation of primitives such as lines and shapes, add them to the appropriate containers, and draw them when called by some other objects.
  • Furthermore, the Axes objects set the coordinate system for the figure and track callbacks that can be connected to the xlim_changed and ylim_changed events. The callbacks will be called with the Axes instances as an argument.
Collections
  • Another component of the artist layer that we will touch on briefly is collections. These are the classes that provide for the effcient drawing of large numbers of similar objects. If you fnd yourself creating tens or hundreds of thousands of circles, polygons, lines, and so on, in most cases you will get much better performance from matplotlib if you put these in collections. The available classes include, but are not limited to PathCollection, CircleCollection, PolyCollection, EllipseCollection, LineCollection, and EventCollection.
如图:

相关文章

  • Matplotlib核心概念

    摘抄自Duncan M. McGreggor所著《Mastering matplotlib》(Packt出版社) ...

  • 2022-03-16

    Matplotlib学习 Day1 1、Matplotlib相关概念 Matplotlib的图像是画在figure...

  • 数据分析工具pandas快速入门教程3绘图3 seaborn

    matplotlib可以被认为是Python中的核心基础绘图工具,seaborn为matplotlib提供更高级别...

  • figure 图像

    Matplotlib的核心是图像,本文通过简单的例子分析Matplotlib的图像绘制过程。 1. 数据准备 2....

  • matplotlib 初步介绍

    matplotlib官方文档 概念 figure The whole figure. The figure kee...

  • 核心概念

    文件格式 文件格式纯文本格式是Robot Framework中最常用的一种数据格式。使用两个或者更多的空格来分隔单...

  • 核心概念

    React 是JavaScript 库,可以快速构建快速响应的大型WEB应用程序。 JSX JSX是一种 J...

  • matplotlib 介绍之event 交互

    上一篇文章粗略介绍了一下matplotlib的基本概念,见matplotlib 初步介绍 之所以写这篇,是记录一下...

  • 进阶学习6-装饰器/迭代器/生成器

    总结 描述备注函数核心概念1函数可以赋值给变量函数核心概念2函数可以作为参数传递函数核心概念3嵌套函数函数核心概念...

  • 关于大概念

    研究大概念案例注意三点: 一、找到内容的核心概念和核心问题 二、理清围绕核心概念和核心问题如何拓展迁移 三、构建大...

网友评论

    本文标题:Matplotlib核心概念

    本文链接:https://www.haomeiwen.com/subject/zzqpvftx.html