The first two articles briefly introduce some common methods of scientific computing numpy, and some other content that will be learned in later examples. Another module,--matplotlib, is described below.
Matplotlib is a Python 2D drawing library that tries to make complex drawing visualizations easier. A few lines of code can generate drawings, histograms, power spectra, bar charts, error plots, scatter plots and other 2D graphics, which we often use in the process of data analysis, the analysis of the results of the drawing process. Matplotlib's documentation, please go to the Portal: https://matplotlib.org/
Let's give a simple example.
1 ImportMatplotlib.pyplot as Plt2 ImportNumPy as NP3 4 #Enter drawing data5 #Here we use some of the methods of the NumPy module6t = Np.arange (0.0, 2.0, 0.01)7s = 1 + np.sin (2 * np.pi *t)8 9 #drawing based on dataTen Plt.plot (t, s) One #set X-axis and y-axis titles APlt.xlabel ('T (s)') -Plt.ylabel ('V (MV)') - #Set Chart title thePlt.title ('Simple pic') - Plt.grid (True) - - #show the drawing in a good shape +Plt.show ()
The result is as follows:
It is worth noting that matplotlib in the display of Chinese, there will be some problems, to solve this problem, please see the Portal: https://www.cnblogs.com/shikaihong/p/7717741.html
Let's look at an example from an official document. (such as infringement contact deletion)
1 #Import this package2 ImportMatplotlib.pyplot as Plt3 ImportNumPy as NP4 5 #define a curve-generated function6 deff (t):7 returnNp.exp (-T) *np.cos (2*np.pi*t)8 9 TenT1=np.arange (0.0,5.0,0.1) OneT2=np.arange (0.0,5.0,0.02) A - #here is the definition canvas, called the canvas one -Plt.figure (1) the - #this declares a new plot area, where the "211" in parentheses indicates that the canvas is divided into two rows, and that the graph is operated on the plot area one -Plt.subplot (211) -Plt.plot (t1,f (T1),'Bo', T2,f (T2),'k') + - #same as above, just operate on two +Plt.subplot (212) A at #the drawing line and color are specified here -Plt.plot (T2,np.cos (2*NP.PI*T2),'r--') - -Plt.show ()
This is
Python Data Analysis Toolkit (3)--matplotlib (i)