Introducción
Matplotlib is a cross-platform Python library for plotting two-dimensional graphs (also called plots). It can be used in a variety of user interfaces such as Python scripts, IPython shells, Jupyter Notebooks, web applications, and GUI toolkits. It can be used to develop professional reporting applications, interactive analytical applications, complex dashboard applications or embed into web/GUI applications. It supports saving figures into various hard-copy formats as well. It also has limited support for three-dimensional figures. It also suports many third-party toolkits to extend its functionality.
Please note that all the examples in this book are tested with Matplotlib 2.2.2 and Jupyter Notebook 5.1.0.
Arquitectura de Matplotlib
Matplotlib has a three-layer architecture: backend, artist, and scripting, organized logically as a stack. Scripting is an API that developers use to create the graphs. Artist does the actual job of creating the graph internally. Backend is where the graph is displayed.
Backend layer
This is the bottom-most layer where the graphs are displayed on to an output device. This can be any of the user interfaces that Matplotlib supports. There are two types of backends: user interface backends (for use in** pygtk
, wxpython
, tkinter
, qt4
, or macosx
, and so on, also referred to as interactive backends) and hard-copy backend to make image files (.pmg
, .svg
, .pdf
, and .ps
, also referred to as non-interactive backends). We will learn how to configure these backends in later Chapter 9
, Developing Interactive Plots and Chapter 10
, Embedding Plots in a Graphical User Interface.
Artist layer
This is the middle layer of the stack. Matplotlib uses the artist
object to draw various elements of the graph. So every element (see elements of a figure) we see in the graph is an artist. This layer provides an object-oriented API for plotting graphs with maximum flexibility. This interface is meant for seasoned Python programmers, who can create complex dashboard applications.
Scripting layer
This is the topmost layer of the stack. This layer provides a simple interface for creating graphs. This is meant for use by end users who don’t have much programming expertise. This is called a pyplot
API.