matplotlib machine learning notes 1

 Scatter -scatter

Scatter plots showing two sets of data values, the coordinate position of each point is determined by the value of the variable is done by a set of points not connected, two types of variables relevant for observation

. 1  Import numpy AS NP
 2  Import matplotlib.pyplot AS PLT   # introduced drawing module 
. 3  
. 4 height = [161, 170., 182, 175, 173, 165 ]
 . 5 weight = [50, 58, 80, 70, 69, 55 ]
 . 6  
. 7  plt.scatter (height, weight)
 . 8 N = 1000
 . 9   X = np.random.randn (N)
 10  # Y1 = np.random.randn (N) 
. 11 Y1 = np.random.randn the -X-+ (N) 0.5 *
 12 is  
13 is  
14  # commands to draw a line scattergram 
15 plt.scatter (X, Y1, S = 100, C = ' R & lt ' , = marker 'O ' , alpha = 0.5 )
 16  # S denotes the area of the point, c denotes the color point, marker showing the shape of dots, alpha represents the point of transparency 
. 17  
18 is plt.show ()

line chart

Is a line graph with line segments connecting the respective pattern data consisting used to observe trends in data over time

. 1  Import numpy AS NP
 2  Import matplotlib.pyplot AS PLT
 . 3  Import matplotlib.dates AS mdates
 . 4  
. 5 X np.linspace = (-10, 10, 100 )
 . 6  
. 7  # Y = X ** 2 
. 8 Y = np.sin ( X)
 . 9  
10 plt.plot (X, Y, linestyle = ' -. ' , color = ' G ' , marker = ' ^ ' )
 . 11  # line graph basic drawing command, linestyle as to draw the line, color the color line, marker for the spot shape 
12  # in matplotlib official website, there are about line, color, shape a comprehensive introduction point 
13 
14 plt.show()

Bar chart

A variable length of the rectangular charts, for comparing a plurality of data items classified size, typically used for small data sets Analysis

Bar can be single, side by side, stacked fashion drawing

 

. 1  Import numpy AS NP
 2  Import matplotlib.pyplot AS PLT
 . 3  
. 4  # single mode 
. 5 N =. 5
 . 6 Y = [20 is, 10, 30, 25, 15 ]
 . 7 index = np.arange (N)
 . 8  
. 9  # plt.bar (index = x, Y = height, width = 0.5, Color = 'R & lt') 
10  # x represents the number of stripes corresponding to the x-axis, y-axis represents a height corresponding to the height of the bar, 
11  # width represents the width of the bars 
12 is plt.bar (index, Y, 0.5, Color = ' R & lt ' )   # X =, = height, width =, may be omitted 
13 is  
14  
15  # bar may be put sideways
16  # X needs to assign a value of 0, bottom bar represents the bottom of the block, i.e., corresponding to the coordinates on the vertical axis, 
. 17  # width bar represents the height of the block placed sideways, corresponding to (lateral) width of the horizontal axis, 
18 is  # height represents the width of the longitudinal bar block, orientation = 'horizontal' represents a transverse bar to be drawn 
. 19 PL = plt.bar (X = 0, index = bottom, Color = ' Red ' , Y = width, height = 0.5 , 
 20 is                   = Orientation ' Horizontal ' )
 21 is  # transverse bar has a second mode, where the y-axis should be the first of several strip fast assignment i.e. index 
22 is  # PL = plt.barh (y = index, Color = 'Red', Y = width,) 
23 is  
24  
25 plt.show ()

 

. 1  Import numpy AS NP
 2  Import matplotlib.pyplot AS PLT
 . 3  
. 4  # tile painted bar, the two bar graphs a common axis, in parallel with the painting 
. 5 index = np.arange (. 4 )
 . 6 sales_BJ = [52,55,63,53 ]
 . 7 sales_SH = [44,66,55,41 ]
 . 8  
. 9 bar_width = 0.3
 10 plt.bar (index, sales_BJ, bar_width, Color = ' B ' )
 . 11  
12 is  # the parallel bars coordinates on the horizontal axis of the chart can be expressed by index + bar_width 
13  # object is not overlapped with the first 
14 plt.bar (index + bar_width, sales_SH, bar_width, Color = ' R & lt')
15 
16 plt.show()
. 1  Import numpy AS NP
 2  Import matplotlib.pyplot AS PLT
 . 3  
. 4  
. 5  # laminated drawing 
. 6 index = np.arange (. 4 )
 . 7 sales_BJ = [52,55,63,53 ]
 . 8 sales_SH = [44,66,55,41 ]
 . 9  
10 bar_width = 0.3
 . 11 plt.bar (index, sales_BJ, bar_width, Color = ' B ' )
 12 is  
13 is  # a second object to be laminated need to add bottom = sales_BJ, showing the object bottom is laminated on a 
14 PLT. bar (index, sales_SH, bar_width, Color = ' R & lt ' , bottom = sales_BJ)
 15 
16 plt.show()

 

Guess you like

Origin www.cnblogs.com/yang901112/p/11417778.html