Using Python's matplotlib graphing

Source: Internet
Author: User
Tags sca

Matplotlib is a Python 2D drawing library that generates publishing quality-level graphics in a variety of hard-copy formats and cross-platform interactive environments.

Bar chart
#Coding:utf-8ImportMatplotlib.pyplot as PltImportNumPy as npplt.rcparams['Font.sans-serif']=['Simhei']label= ['G1','G2','G3','G4','G5']x= Sorted ([1234, 221, 765, 124, 2312]) IDX=Np.arange (len (x)) color= Cm.jet (Np.array (x)/Max (x)) Plt.barh (idx, x)#Plt.bar () Verticalplt.yticks (IDX, label) Plt.grid (Axis='x')plt.show ()

Pie chart
#Coding:utf-8ImportMatplotlib.pyplot as pltplt.rcparams['Font.sans-serif']=['Simhei']labels= [u'First Part', u'Part II', u'Part III']sizes= [60,30,10]colors= ['Red','Yellowgreen','Lightskyblue']#explode a part, use parentheses, divide the first block, the size of the value is divided with the other two pieces of the gapExplode = (0.05, 0,0)#Data ImportPlt.pie (sizes,labels=labels,explode=explode,colors=colors,autopct ='%3.1f%%', StartAngle = 90)#Labeldistance, the position of the text is far from the far point, 1.1 refers to the position of 1.1 times times the radius#autopct, the text format inside the circle,%3.1f%% indicates that the decimal has three bits, and the integer has a floating-point number#startangle, starting angle, 0, indicates that the first block is rotated counterclockwise from 0. General selection from 90 degrees to look betterPlt.axis ('Equal')#set the x, Y axis scale to match so that the pie chart can be roundedplt.legend () plt.show ( )

Sub-chart, line chart
#Coding:utf-8ImportNumPy as NPImportMatplotlib.pyplot as Pltplt.figure (2)#creating a diagram 2Ax1=plt.subplot (211)#Create a sub-figure in chart 2 1Ax2=plt.subplot (212)#Create a sub-figure in chart 2 2X=np.linspace (0,3,100)#generates a vector of 0 to 3, divided into 100 parts forIinchXrange (5): Plt.sca (AX1) plt.plot (X,np.sin (i*x)) Plt.sca (AX2) plt.plot (X,np.cos (i*x)) Plt.show ()

Using Python's matplotlib graphing

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.