1. System EnvironmentSystem: CentOS 6.7 64-bit python:2.6.6 (System with self) Ide:pycharm Community Edition
2. Build the drawing environment#yum Install Python-matplotlib
3. DrawingThe first example, very classic, draws the point line diagram code as follows:
#!/usr/bin/python
import NumPy as NP
import Pylab as pl
x = [1, 2, 3, 4, 5] # make an array of x VALUES
y = [1, 4, 9, X] # make a array of y values for each x value
pl.plot (x, y) # use Pylab to plot x and Y
pl.show () # show the ' plot on the ' screen
Effect as shown:
Change Pl.plot (x, y) to Pl.plot (x, y, ' o ') to get the following figure:
-------------------------------------------------
The second example, the code is as follows:
#!/usr/bin/python
import NumPy as NP
import Matplotlib.pyplot as plt
xData = Np.arange (0, 1)
yData1 = XDATA.__POW__ (2.0)
yData2 = Np.arange (5)
plt.figure (Num=1, figsize= (8, 6))
plt.title (' Plot 1 ', SIZE=14)
Plt.xlabel (' x-axis ', size=14)
Plt.ylabel (' Y-axis ', size=14)
plt.plot (XData, yData1, color= ' B ') , linestyle= '--', marker= ' o ', label= ' y1 data ')
Plt.plot (XData, YData2, color= ' R ', linestyle= '-', label= ' y2 data ') C11/>plt.legend (loc= ' upper left ')
plt.savefig ('/home/plot1.png ', format= ' png ')
The effect of the following figure:
----------------------------------------------------------
The third example is the following code
#!/usr/bin/python
import NumPy as NP
import Matplotlib.pyplot as plt
x = np.linspace (0, 1000)
y = Np.s In (x)
z = Np.cos (x**2)
plt.figure (figsize= (8,4))
plt.plot (x,y,label= "sin (x)", color= "Red", linewidth=2 )
Plt.plot (x,z, "b--", label= "cos (x^2)")
Plt.xlabel ("Time (s)") Plt.ylabel (
"Volt")
Plt.title (" Pyplot-Example ")
Plt.ylim ( -1.2,1.2)
plt.legend ()
plt.show ()
The effect of the following figure:
4. Reference Documents[1] http://www.jb51.net/article/67626.htm [2] http://old.sebug.net/paper/books/scipydoc/matplotlib_intro.html [3] Http://www.cnblogs.com/wei-li/archive/2012/05/23/2506940.html
---