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