matplotlib the subplot usage

Figure object contains a plurality of sub-graphs, you can use the subplot () function to draw the sub-picture:

  (First of all I do not want to understand why there is so much content to introduce this function, we later learned that the original content of this function really a lot of)

   Concise:

   First, it calls is like this: subplot (numbRow, numbCol, plotNum) or subplot (numbRow numbCol plotNum), right. See, you can not write directly to a comma separated together is right;

   Please explain how this hell:

   FIG numbRow plot of the number of rows; numbCol FIG plot of the number of columns; plotNum refers to the several figures of the first few lines of the columns;

   For example, if a subplot (2, 2, 1), then this figure is a matrix of Figure 2 * 2, which is a total of 4 Figure 1 represents the first picture

   Can also be written subplot (221), which is not wrong Kazakhstan. It is not a super simple! Last figure:

 

That did not, I wrote a diagram salt and pepper noise, then subplot can be divided write, but I used a form of the cycle;

 

Yes, there is a form almost forgot to say, if it is only a single or only a few 3 Figure 5 Figure of how to do?

 

Cycle operation can not be used here because of FIG 3, then divided up and rearranged to give:

  What do you mean? For example, draw a picture of three drawing:

  First, the entire table in accordance with the 2*2divided
  first two simple, respectively (2, 2, 1), and(2, 2, 2)

  But the third figure, he takes up (2, 2, 3)and(2, 2, 4)

  They then need to re-divide them, according to 2 * 1division

  The first two map takes up (2, 1, 1)position

  FIG therefore occupies third (2, 1, 2)position

  Directly on the code we look at, in fact, very much the same, grammar are similar;   

import matplotlib.pyplot as plt
import numpy as np

def f(t):
    return np.exp(-t) * np.sin(2 * np.pi * t)


if __name__ == '__main__':
    t1 = np.arange(-5, 5, 0.1)
    t2 = np.arange(-5, 5, 0.2)
    plt.figure()
    plt.subplot(221)
    plt.plot(t1, f(t1), 'bo', t2, f(t2), 'g--')
    plt.subplot(222)
    plt.plot(t2, np.cos(2 * np.pi * t2), ' g-- ' ) 
    plt.subplot ( 212 ) 
    plt.plot ([ 1, 2, 3, 4], [1, 4, 9, 16 ]) 
    plt.show ()

  Then this is the result of the show:

Well, basically almost here already, and we learn it?

 

Guess you like

Origin www.cnblogs.com/caizhou520/p/11224526.html