关于*kwargs,有时候,函数的参数里会有(*args, *kargs),都是可变参数,*args表示无名参数,是一个元租,**kwargs是键值参数,相当于一个字典,比如你输入参数为:(1,2,3,4,k,a=1,b=2,c=3),*args=(1,2,3,4,k),**kwargs={'a':'1,'b':2,'c':3}
如果同时使用这两个参数,*args要在**kwargs之前,不能是:a=1,b=2,c=3,1,2,3,4,k,这样会出现语法错误提示:SyntaxError:non-keyword arg after keyword arg
*kwargs 还可以用来创建字典哦:
def dicmake(**kwargs):
return kwargs
(很鸡肋啦,Python本来就自带dic()来建立字典)
http://matplotlib.org/api/lines_api.html#matplotlib.lines.Line2D
Bases: matplotlib.artist.Artist
class matplotlib.lines.Line2D(xdata, ydata, linewidth=None, linestyle=None, color=None, marker=None, markersize=None, markeredgewidth=None, markeredgecolor=None, markerfacecolor=None, markerfacecoloralt='none', fillstyle=None, antialiased=None, dash_capstyle=None, solid_capstyle=None, dash_joinstyle=None, solid_joinstyle=None, pickradius=5, drawstyle=None, markevery=None, **kwargs)
Property | Value Type |
---|---|
alpha | 控制透明度,0为完全透明,1为不透明 |
animated | [True False] |
antialiased or aa | [True False] |
clip_box | a matplotlib.transform.Bbox instance |
clip_on | [True False] |
clip_path | a Path instance and a Transform instance, a Patch |
color or c | 颜色设置 |
contains | the hit testing function |
dash_capstyle | [‘butt’ ‘round’ ‘projecting’] |
dash_joinstyle | [‘miter’ ‘round’ ‘bevel’] |
dashes | sequence of on/off ink in points |
data | 数据(np.array xdata, np.array ydata) |
figure | 画板对象a matplotlib.figure.Figure instance |
label | 图示 |
linestyle or ls | 线型风格[‘-’ ‘–’ ‘-.’ ‘:’ ‘steps’ …] |
linewidth or lw | 宽度float value in points |
lod | [True False] |
marker | 数据点的设置[‘+’ ‘,’ ‘.’ ‘1’ ‘2’ ‘3’ ‘4’] |
markeredgecolor or mec | any matplotlib color |
markeredgewidth or mew | float value in points |
markerfacecolor or mfc | any matplotlib color |
markersize or ms | float |
markevery | [ None integer (startind, stride) ] |
picker | used in interactive line selection |
pickradius | the line pick selection radius |
solid_capstyle | [‘butt’ ‘round’ ‘projecting’] |
solid_joinstyle | [‘miter’ ‘round’ ‘bevel’] |
transform | a matplotlib.transforms.Transform instance |
visible | [True False] |
xdata | np.array |
ydata | np.array |
zorder | any number |
有三种方式设置线的属性
1)直接在plot()函数中设置
plt.plot(x, y, linewidth=2.0)
2)通过获得线对象,对线对象进行设置
line, = plt.plot(x, y, '-')
line.set_antialiased(False) # turn off antialising
3)获得线属性,使用setp()函数设置
lines = plt.plot(x1, y1, x2, y2)
# use keyword args
plt.setp(lines, color='r', linewidth=2.0)
Matplotlib 颜色样式快捷设置
一个应用,在图上做一条垂直于x轴的线段,要用两个相同x,不同y的点来刻画
plt.plot([x,x],[0,y])