matplotlib

import matplotlib.pyplot as plt

plt.figure()
生成一个窗口

plt.plot()
画图,自己可以查看输入的两个参数,它们是长度相等的两个集合

plt.show()
没什么好说的,就是显示图像


画多个曲线,就用多个plt.plot()

plt.plot(x,y1)
plt.plot(x,y2)

plot 还有三个比较有用的参数

color='red', linewidth=1.0, linestyle='--'

顺便说一下python中的args 和*kwargs问题

args
当传入一组参数时,会先匹配前面的,剩下的都会作为
args
*args可以是list(列表[])或tuple(元组())

列表中的元素可以是各种类型的,元组和列表类似,只不过元素不能修改

例子:

def fun_var_args(farg, *args):
    print "arg:", farg
    for value in args:
        print "another arg:", value

fun_var_args(1, "two", 3) # *args可以当作可容纳多个变量组成的list

arg: 1
another arg: two
another arg: 3

linestyle、 color、 marker?

matplotlib.pyplot.plot(*args, **kwargs)

character   description
'-' solid line style
'--'    dashed line style
'-.'    dash-dot line style
':' dotted line style
'.' point marker
',' pixel marker
'o' circle marker
'v' triangle_down marker
'^' triangle_up marker
'<' triangle_left marker
'>' triangle_right marker
'1' tri_down marker
'2' tri_up marker
'3' tri_left marker
'4' tri_right marker
's' square marker
'p' pentagon marker
'*' star marker
'h' hexagon1 marker
'H' hexagon2 marker
'+' plus marker
'x' x marker
'D' diamond marker
'd' thin_diamond marker
'|' vline marker
'_' hline marker
The following color abbreviations are supported:

character   color
‘b’ blue
‘g’ green
‘r’ red
‘c’ cyan
‘m’ magenta
‘y’ yellow
‘k’ black
‘w’ white

你可能感兴趣的:(matplotlib)