English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Matplotlib Tutorial

Matplotlib is one of the most popular Python packages for data visualization. It is a cross-platform library that creates2Figure D. It provides an object-oriented API that helps to embed plotting in applications using Python GUI toolkits (such as PyQt, WxPython, or Tkinter). It can also be used in Python and IPython shells, Jupyter notebooks, and web application servers.

Target Audience

This tutorial is designed for learners who wish to obtain basic knowledge of data visualization.

Prerequisites

Matplotlib is written in Python and uses Python's numerical mathematics extension NumPy. We assume that the readers of this tutorial have a basic understanding of Python.

Problem Feedback

The explanations, examples, and code in this tutorial are only summarized based on the author's understanding. Due to the limitations of the author's level and ability, it cannot be guaranteed that all the written articles and examples are accurate and error-free. However, if any errors or problems are encountered, please feedback to us, and we will correct them in a timely manner for the convenience of subsequent readers.

Tutorial directory

The main content of this tutorial is as follows -

Introduction to Matplotlib - Matplotlib is one of the most popular Python packages for data visualization. It is a cross-platform library that creates2Figure D.Matplotlib Development Environment - Matplotlib and its dependencies are provided in the standard Python package repository in the form of wheel packages, which can be installed on Windows, Linux, and MacOS systems using the pip package manager.Matplotlib Anaconda development tools - Anaconda is a free and open-source distribution for Python and R programming languages, used for large-scale data processing, predictive analysis, and scientific computing.Matplotlib Jupyter Notebook - Jupyter is an abbreviation, meaning Julia, Python, and R. These programming languages are the first target languages for Jupyter applications, but now, Jupyter technology also supports many other languages.Matplotlib Pyplot API - matplotlib.pyplot is a collection of command-style functions that make Matplotlib work like MATLAB. Each Pyplot function makes some changes to the graph.Matplotlib Simple Plotting - Display a simple angle line chart in radians corresponding to the sine value in Matplotlib.Matplotlib pylab Module - PyLab is a very convenient module that can batch import matplotlib.pyplot (for plotting) and NumPy (for mathematics and using arrays) in a single namespace.Matplotlib Object-Oriented Interface - In the object-oriented interface, Pyplot is used only for some functions, such as figure creation, and users explicitly create and track figure and axis objects. At this level, users create figures using Pyplot, through which one or more axis objects can be created.Matplotlib Figure Class - The matplotlib.figure module contains the Figure class. It is the top-level container for all plot elements.Matplotlib Axes Class - Axes objects are image regions with data spaces. A given figure can contain many axes, but a given Axes object can only be in one figure. Axes contain two (or more) in some cases.3In case D, there are three Axis objects.Matplotlib Multiplots - In this chapter, we will learn how to create multiple subplots on the same canvas.
The subplot() function returns the axes object at the given grid position.
Matplotlib subplots() Function - Matplotlib's pyplot API has a convenient function called subplots(), which acts as a utility wrapper and helps create a common layout for subplots in a single call, including the enclosed figure object.Matplotlib subplot2grid() function - Matplotlib subplot2The grid() function provides greater flexibility in creating axis objects at specific positions in the grid. It also allows axis objects to span multiple rows or columns.Matplotlib Grid - The grid() function of the axes object sets the visibility of the grid in the plot to on or off. It can also display the main grid./Secondary (or both) scales.Matplotlib Axis Formatting - The axis scale needs to be set to logarithmic (log) rather than normal scale. This is logarithmic scale. In Matplotlib, this can be done by setting the xscale or vscale attribute of the axes object to log.Matplotlib Setting Limits - Matplotlib automatically adjusts to the x, y (and3In the case of D plot, the axis showing the minimum and maximum values of the variable (in the case of z-axis) but can be used with set-xlim() and set-The ylim() function explicitly sets the limits.Matplotlib Setting Ticks and Tick Labels - Ticks are the markers that represent data points on the axis. So far, Matplotlib has automatically taken over the task of interval points on the axis in all our previous examples.Matplotlib Dual Axes - When plotting curves with different units, Matplotlib supports this feature through the twinx() and twiny() functions.Matplotlib Bar Chart - Bar charts or bar graphs are a chart or graphic that displays categorical data with rectangular bars, whose height or length is proportional to the value they represent. Bars can be drawn vertically or horizontally.Matplotlib Histogram - Histograms are an accurate representation of the distribution of numerical data. It is an estimate of the probability distribution of a continuous variable and is a type of bar chart.Matplotlib Pie Chart - Pie charts can only display a series of data. In a pie chart, the size of items (called wedges) in a data series is displayed, proportional to the total of the items. Data points in the pie chart are shown as a percentage of the entire pie.Matplotlib Scatter Plot - Scatter plots are used to plot data points on horizontal and vertical axes to try to show the extent to which one variable affects another. Each row in the data table is represented by a marker, whose position depends on the value set in the column of the X and Y axes it is set to.Matplotlib Contour Plot - Contour plots (sometimes called 'level plots') are a method to display three-dimensional surfaces on a two-dimensional plane. They plot the predicted variables X and Y on the y-axis and the response variable Z of the contour. These contours are sometimes called z-slices or isoresponses.Matplotlib 2D Arrow Plot - Arrow plots display velocity vectors as arrows, with components (u, v) located at the point (x, y).Matplotlib Box Plot - Box plots, also known as whisker plots, show the summary of a set of data containing the minimum value, the first quartile, the median, the third quartile, and the maximum value. In the box plot, a box is drawn from the first quartile to the third quartile. The vertical line crosses the middle box. The whiskers extend from each quartile to the minimum or maximum value.Matplotlib Violin Plot - Violin plots are similar to box plots, but they also show the probability density of different values. These plots include the median of the data marked and the box representing the range of the quartiles, as shown in the standard box plot.Matplotlib 3D Plotting - Matplotlib was initially designed to consider only two-dimensional plotting, but in later versions, some three-dimensional plotting utilities have been built on the two-dimensional display of Matplotlib to provide a set of three-dimensional data visualization tools.
28.Matplotlib 3D contour plot - ax.contour3The D() function creates a three-dimensional contour plot. It requires all input data to be in the form of a two-dimensional regular grid and to evaluate Z data at each point.
Matplotlib 3D wireframe plot - Wireframe plots project a value grid onto a specified three-dimensional surface and can make the resulting three-dimensional form very easy to visualize.Matplotlib 3D surface plot - Surface plots show the functional relationship between the specified dependent variable (Y) and two independent variables (X and Z). This plot is an accompanying plot to the contour plot. Surface plots are similar to wireframe plots, but each face of the wireframe is filled with a polygon.Using Text in Matplotlib - Matplotlib has extensive text support, including support for mathematical expressions, TrueType support for raster and vector output, text with line breaks at arbitrary rotations, and unicode support.Matplotlib Mathematical Expressions - Place the TeX markup subset of any Matplotlib text string within a pair of dollar signs ($).Matplotlib uses images - The image module in the Matplotlib package provides the functionality required to load, resize, and display images, with the Pillow library supporting image data loading. Matplotlib supports PNG images only.Matplotlib transformations - matplotlib package is built on top of a transformation framework, allowing easy movement between coordinate systems. Four coordinate systems can be used.

Matplotlib is one of the most popular Python packages for data visualization. It is a cross-platform library that creates2D figure. Matplotlib is written in Python and uses the Python numerical mathematics extension NumPy. It provides an object-oriented API that helps to embed plotting in application with Python GUI toolkits (such as PyQt, WxPython, or Tkinter). It can also be used in Python and IPython shells, Jupyter notebooks, and web application servers.

Matplotlib has a process interface named Pylab, which is designed to be similar to MATLAB, a proprietary programming language developed by MathWorks. Matplotlib andNumPyand can be considered as an open-source equivalent of MATLAB.

Matplotlib was originally developed by John D. Hunter in2003Written in2018year1Published in2.2.0.