Home > Backend Development > Python Tutorial > Python uses add_subplot and subplot to draw subplots

Python uses add_subplot and subplot to draw subplots

不言
Release: 2018-06-02 14:34:57
Original
15878 people have browsed it

This article mainly introduces the operation of Python using add_subplot and subplot to draw subplots, and involves the related operating skills of Python using the matplotlib module for graphics drawing. Friends in need can refer to it

The examples in this article describe the use of Python add_subplot and subplot draw subplot operations. Share it with everyone for your reference, the details are as follows:

Sub-pictures: is to generate multiple sub-pictures in one figure.

Introduction to Matplotlib objects

FigureCanvas Canvas
Figure Figure
Axes Coordinate axis (where the actual drawing is done)

Note that the plt.subplot() parameters in the pyplot method are the same as the add_subplot() parameters and meanings in the object-oriented method.

Use object-oriented approach

#!/usr/bin/python
#coding: utf-8
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(0, 100)
fig = plt.figure()
ax1 = fig.add_subplot(221)
ax1.plot(x, x)
ax2 = fig.add_subplot(222)
ax2.plot(x, -x)
ax3 = fig.add_subplot(223)
ax3.plot(x, x ** 2)
ax4 = fig.add_subplot(224)
ax4.plot(x, np.log(x))
plt.show()
Copy after login

pyplot approach

#!/usr/bin/python
#coding: utf-8
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(0, 100)
plt.subplot(221)
plt.plot(x, x)
plt.subplot(222)
plt.plot(x, -x)
plt.subplot(223)
plt.plot(x, x ** 2)
plt.subplot(224)
plt.plot(x, np.log(x))
plt.show()
Copy after login

Running results:

Related recommendations:

Python uses Windows API to create windows Example

The above is the detailed content of Python uses add_subplot and subplot to draw subplots. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template