Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the underlying principle of Python matplotlib?

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the relevant knowledge of "what is the underlying principle of Python matplotlib". In the operation of actual cases, many people will encounter such a dilemma. Then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

1. Composition of matplotlib framework

Matplotlib module can realize complex underlying operations in many data visualization libraries. For example, gglot, seaborn and plotnline are all based on matplotlib module to encapsulate different styles of statistical charts.

The bottom layer of matplotlib module is mainly composed of three parts: script layer, art layer and back-end layer.

Script layer: provides users with an interface for visual programming

Art layer: an interface with a large number of charting methods

Backend: interface for connecting hardware and processing image elements

PS:matplotlib framework description

two。 Script layer (scripting)

Script layer belongs to the top layer of matplotlib module, which mainly provides users with visual programming interface, representing pyplot module.

For ordinary users, the pyplot interface can satisfy the generation of most text images and coordinates, which can be transmitted to the back end for processing.

When the matplotlib.pyplot interface is imported, it is usually import matplotlib.pyplot as plt

Import the pyplot module and rename it plt

When the pyplot module is loaded, the local configuration file is analyzed

The default backend is also declared, such as declaring the creation of a Figure object

Deeply copy the script to the backend and exit

The method of calling matplotlib in pyplot Module

Supply with oo-oriented call style, display to create graphics and axis call method

Rely on pyplot to automatically create and manage drawings and axes, and use the pyplot function to draw

Users only need to call the methods related to the pyplot module to draw a beautiful chart.

From matplotlib import pyplotimport pandaspyplot.rcParams ["font.sans-serif"] = ['SimHei'] pyplot.rcParams ["axes.unicode_minus"] = Falsepyplot.bar ([1Jing 2 Jing 3 Jing 4 Jing 5 Jing 6], [45 Yue 20 Jing 19Zhi 56 551 569]) pyplot.title ("data analyze") pyplot.xlabel ("element a") pyplot.ylabel ("element b") pyplot.show ()

3. Art floor (artist)

The art layer is located in the middle layer of matplotlib, which mainly carries on the data-related drawing work, and the title, line and scale in the chart are all examples of artist objects.

Characteristics of artist layer

The Figure object created by the script layer is an instance of the Artist object

The base class of Artist is matplotlib.artist.Artist, which shares all Artist attributes, including changes from the art system to the canvas coordinate system.

Provides an interface for handling user interactions

Matplotlib Chart object

We can see from the following matplotlibe chart that a chart is composed of multiple objects.

Matplotlib Chart object description

Object description Figure graph, pop-up box mouth is figureaxes subgraph title title legend legend Major tick large scale scale Minor tick small scale Linetype chart axis label coordinate index description Marker data standard description

Artist object description

The ArtIst object contains Figure, Axes, and Axis objects, which are their base classes, and their Artist objects are all on the canvas canvas provided by the back end.

Figure

A chart window is a figure object.

At least one Axes object subgraph must be included in the figure object

Figure objects can contain Artist objects such as title, label, etc.

The invisible object canvas contained in the figure object. Call is made when the image is drawn

Axes

Axes is a subgraph object, which refers to the x and y axes.

Axes commonly used set_xlabel (), set_ylabel () setting x and y axis coordinate names

Axis

Axis is an object that represents the data axis and is mainly used to represent the position of the scale and display values.

Axis contains two sub-objects, Locator and display scale Formatter, which are used to control the position of the scale.

The Artist object hierarchy diagram is as follows

4. Back-end layer (backend)

The back-end layer is mainly implemented at the bottom of the matplotlib module, which mainly implements three aspects of abstract interface 4.

FigureCanvas: encapsulates the canvas function of Artist object drawing

The bottom layer of the matplotlib module is based on the hard user screen, and the FigureCaves interface mainly completes the preliminary initialization work.

Embed itself into the native QT visual window (QtGui.QMainWindow)

Convert the drawing command Render of matplotlib to canvas (QtGui.QPainter)

The native Qt event is converted to the Event interface of matplotlib, and the Event interface receives the information and processes it.

Renderer: equivalent to a paintbrush, performing a paint action

Render mainly provides the drawing interface at the bottom of the hardware, which can execute Artist drawing commands.

The Render interface originally originated from GDK's Drawable interface and was later converted into a separate back-end native drawing command.

Matplotlib is supported by C++ module library based on pixel core renderer agg

Can perform 2d anti-aliasing rendering and PNG image generation

Event: handling user keyboard and mouse input events

The Event framework maps UI events such as key-press-event or mouse-motion-event to keyboard or mouse event classes.

Users can connect events and use functions to make callbacks

Interaction between graphics and data

This is the end of the content of "what is the underlying principle of Python matplotlib". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report