When we follow the previous blog post
http://blog.csdn.net/tao_627/article/details/44004541
After you have configured your Python drawing environment, here are a few representative examples:
I. Drawing of a bar chart
#!/usr/bin/env_python
#encoding: utf-8
import Matplotlib.pyplot as PLT
def bar_chart_generator ():
l =[1,2,3,4,5]
h=[20,14,38,27,9]
w=[0.1,0.2,0.3,0.4,0.5]
b=[1,2,3,4,5]
fig=plt.figure ()
ax= Fig.add_subplot (Rects=ax.bar) (
l,h,w,b) plt.show ()
bar_chart_generator ()
Two. Draw the graph
#!/usr/bin/env_python
#encoding: Utf-8
#usage: Python curve_demo.py
import matplotlib.pyplot as Plt
Import NumPy as NP
#To draw y=x^2 ( -3<=x<=3)
x = Np.arange ( -3,3.5,0.5)
y = [ele**2 for ele in x]
z = [Ele *2 for Ele in X]
Fig = plt.figure (1)
ax = fig.add_subplot (211)
line1 = Ax.plot (x,y, ' ro-')
ax = fig.add_subplot (212)
Line2 = Ax.plot (x,z, ' G ')
plt.show ()
Three. Draw a line chart
#!/usr/bin/env_python #encoding: Utf-8 import numpy as NP import Pylab as PL from Stringio import stringio data_str = "" "2012-04-01_02 68 2012-04-01_05 70 2012-04-01_08 69 2012-04-01_11 71 2012-04-01_14 72 2012-04-01_20 70 2012-04-02_ 02 71 2012-04-02_05 70 2012-04-02_08 69 2012-04-02_11 71 2012-04-02_14 69 2012-04-02_20 71 2012-04-03_02 74 2012-04 -03_05 73 2012-04-03_08 77 2012-04-03_11 70 2012-04-03_14 71 2012-04-03_20 70 2012-04-04_02 70 2012-04-04_05 72 201 2-04-04_08 2012-04-04_11 2012-04-04_14 2012-04-04_20 2012-04-05_02 "" "" "Data = Np.loadtxt (Stringio (DAT A_STR), Dtype=np.dtype ([("T", "S13"), ("V", float)]) Datestr = Np.char.replace (data["T"], "_", "") T = Pl.datestr2num (d ATESTR) v = data["V"] pl.plot_date (t, V, fmt= "-O") pl.subplots_adjust (bottom=0.3) ax = PL.GCA () ax.fmt_xdata = pl. Dateformatter ('%y-%m-%d%h:%m:%s ') pl.xticks (rotation=90) pl.xticks (T, datestr) # If the data point is a scale, the line is commented out ax.xaxis.set_ Major_formatter (pl. Dateformatter ('%y-%m-%d%H ')) Pl.grid () pl.show ()
Reference documents
[1].http://blog.sina.com.cn/s/blog_68b606350101ryao.html