Python--matplotlib Library use 2

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.