python图 链接矩阵法
Many times while plotting a figure, we have to compare different functions simultaneously. Then we do have the option to plot in a single figure but this is helpful only for a limited number of functions. If there are a greater number of functions, then plotting in the same figure turns out to be messy. Therefore, matplotlib provides a feature of subploting in which we can plot more than one plot in one figure with more than one graph. Matrix Subplotting is a type of subplotting when we have subplots in a matrix format and a large number of figures can be compared. For example, population data of multiple countries.
绘制图形很多时候,我们必须同时比较不同的功能。 然后,我们确实可以选择绘制单个图形,但这仅对有限数量的功能有用。 如果有更多的功能,则在同一图中绘制会变得很混乱。 因此,matplotlib提供了细分功能,其中我们可以在一个图形中绘制多个图形,并在多个图形中绘制图形。 当我们具有矩阵格式的子图并且可以比较大量图形时,矩阵子图就是一种子图。 例如,多个国家的人口数据。
![Python | Matrix Subplot (1)](https://i-blog.csdnimg.cn/blog_migrate/8930db3da21da2a0dbd2c4a6a84af4bf.png)
Syntax:
句法:
#Matrix plotting in a one figure
plt.figure()
plt.subplot(2, 3, 1)
#plt.title('1')
plt.subplot(2, 3, 2)
#plt.title('2')
plt.subplot(2, 3, 3)
#plt.title('3')
plt.subplot(2, 3, 4)
#plt.title('4')
plt.subplot(2, 3, 5)
#plt.title('5')
plt.subplot(2, 3, 6)
#plt.title('6')
plt.show()
![Python | Matrix Subplot (2)](https://i-blog.csdnimg.cn/blog_migrate/fe42f3346f47d195a1f3007ea068cc35.png)
矩阵子图的Python代码 (Python code for matrix subplot)
# Data Visualization using Python
# Matrix Subploting
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(50)
# Example 1 : Default Subplot
plt.figure(figsize=(20,15))
plt.title('MAtrix Subploting')
plt.subplot(2, 3, 1)
plt.plot(x, np.random.randint(0,50,50))
plt.title('1')
plt.subplot(2, 3, 2)
plt.plot(x, np.random.randint(0,50,50), 'r--')
plt.title('2')
plt.subplot(2, 3, 3)
plt.plot(x, np.random.randint(0,50,50), 'b-')
plt.title('3')
plt.subplot(2, 3, 4)
plt.plot(x, np.random.randint(0,50,50), '.-')
plt.title('4')
plt.subplot(2, 3, 5)
plt.plot(x, np.random.randint(0,50,50), '.')
plt.title('5')
plt.subplot(2, 3, 6)
plt.plot(x, np.random.randint(0,50,50), 'g')
plt.title('6')
plt.show()
Output:
输出:
Output is as figure
python图 链接矩阵法