2-4 Numpy + Matplotlib visualized (II)

Custom painting

. 1  # - * - Coding: UTF-. 8 - * - 
2  # ! / Usr / bin / the env Python 
. 3  # the Author: @vilicute 
. 4  
. 5  Import numpy AS NP
 . 6  Import matplotlib.pyplot AS PLT
 . 7  
. 8  DEF draw_line ():
 . 9      '' ' 
10      plotted
 . 11      ' '' 
12 is      Figure plt.figure = ( ' Line Demo ' )
 13 is      X = np.linspace (0, 10, 100) # (start value, the final value, the number of intervals) 
14      Y = . 1 / (. 1 - np.exp (the -X-** 2 ))
 15      plt.plot (X, Y)
 16     plt.show()
17 
18 def draw_lines():
19     figure = plt.figure('Lines Demo')
20     x = np.linspace(-10, 10, 100)
21     y1 = 1
22     y2 = np.sin(x)
23     y3 = np.sinc(x)
24     plt.plot(x, y2, 'b-', x, y3, 'g-')
25     plt.show()
26 
27 def draw_pie():
28     '''
29     绘制饼图
30     '''
31 is      Figure plt.figure = ( ' Pie Demo ' )
 32      Labels = ' A ' , ' B ' , ' C ' , ' D '     # names of each part 
33 is      sizes = [40, 25, 20 is, 15]         # share percentage 
34 is      the explode = [0.01, 0, 0.02, 0]     # spacer block 
35      plt.pie (sizes, = Labels Labels, the explode = the explode, autopct = ' % 1.1f %% ' , startAngle = 90 )
 36      PLT. Axis ( ' equal' )
 37 [      plt.show ()
 38 is  
39  DEF draw_hist ():
 40      ' '' 
41 is      histogrammed
 42 is          numpy.random.seed () can be made of the same random number generated multiple times. If the incoming SEED () in the same figure, then used next
 43 is      random () or rand () method of the generated random number sequence is the same (random only once () or rand () method of secondary to
 44      and still more times random number), changing the value of the incoming know SEED (), and after the change back, random () is still generated random number sequence with
 45      identical sequences previously generated.
46 is      '' ' 
47      np.random.seed (20,190,308 );
 48      Figure plt.figure = ( ' Pie Demo ' );
 49      plt.hist (np.random.rand (30), 20 is, histtype = 'bar ' , facecolor = ' G ' , Alpha = 0.75, Rwidth = 0.95 );
 50      plt.show ();
 51 is  
52 is  DEF draw_bar ():
 53 is      '' ' 
54 is      drawn bar
 55      ' '' 
56 is      Figure PLT =. Figure ( ' Pie Demo ' )
 57 is      Labels = ' A ' , ' B ' , ' C ' , ' D ' 
58      sizes = [12 is, 23 is,. 5, 31 is ]
 59     plt.bar(labels, sizes, width=0.5)
60     plt.show()
61 
62 
63 def draw_function():
64     x = np.arange(-25, 25, 0.01)
65     y1 = 1.25 * np.sqrt(x ** 2 - 16)
66     y2 = -1.25 * np.sqrt(x ** 2 - 16)
67     plt.xlabel('x')
68     plt.ylabel('y')
69     plt.plot(x, y1)
70     plt.plot(x, y2)
71 
72     plt.show()
73 
74 draw_function()
75 draw_line()
76 draw_lines()
77 draw_pie()
78 draw_hist()
79 draw_bar()

 

draw_function(),draw_line(),draw_lines()                  

 

 

draw_pie(),draw_hist() ,draw_bar()

 

 

Guess you like

Origin www.cnblogs.com/vilicute/p/11608090.html