function : Python draw 2D graph
Directly on the code, the comments are very detailed!
1 #-*-coding:utf-8-*-2 3 fromNumPyImport*4 ImportMatplotlib.pyplot as Plt5 6A=array ([0,0]); B=array ([[1,0],[0,1]])7 #generates a as mean, B is the covariance matrix, and satisfies the random number of the normal distribution8C1=random.multivariate_normal (a,b,10)#10*29C2=random.multivariate_normal (a+0.1,b+0.1,20)#20*2TenC2=mat (C2)#This is done just to illustrate the difference between Ndarray and matrix data One AFig=plt.figure (figsize= (5,5))#Make canvas size -Ax=fig.add_subplot (111) - the #Ndarray Data C1,shpe (C1) obtained (10L), matrix type C=mat (C1), SHPE (c[:,1]) obtained (10L,1L) -Ax.scatter (c1[:,0],c1[:,1],s=50,c='R', marker='o', alpha=0.5,label='C1') -Ax.scatter (C2[:,0].flatten (). A[0],c2[:,1].flatten (). A[0],s=30,c='b', marker='^', alpha=0.5,label='C2') - " " + Scatter (x,y,x=none,c=none,marker=none) - x, y must be 1-d + marker is a marker, s controls the size of the marker, C controls the color of the marker A Flatten () function: A.flatten (), get a copy that converts a to 1-d at in addition, the matrix (that is, Mat (a)) has a property and can use Mat (a). Flatten (). A[0], get a 1-d "array" - " " -Plt.title ('Scatter plot') -Plt.xlabel ('The Variable X') -Plt.ylabel ('The Variable Y') - inAx.legend (loc='Upper Left')#Determine the box position -Plt.show ()
About the official Pyplot.scatter () function in detail see: Http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.scatter
Python--matplotlib Library use 2