pyplot tutorial (翻译)

(第二部分)控制线属性 controlling line properties

直线有许多可以设置的属性:线宽(linewidth),点画线风格(dashstyle),反锯齿效果(antialiased)等等。具体可以看 matplotlib.lines.Line2D。

这里有几种方式可以设置直线的属性

1、使用关键字参数(keyword args):

plt.plot(x,y,linewidth=2.0)

2、使用Line2D实例的设置器(setter methods)方法。
plot 返回一个Line2D对象的列表(list);例如
line1,line2 = plot(x1,y1,x2,y2)。在下面的代码中,我们假定(suppose)只有一个线(line),所以返回的列表的长度是1。我们可以使用元组(tuple)来解包返回的line列表,如下方式可以得到返回列表的第一个元素:

line, = plt.plot(x,y,'-')#注意等号左侧的逗号
line.set_antialiased(False)#setter method

3、使用 setp()命令
下面的例子使用了MATLAB风格的命令对列表中的多个线(line)设置多个属性。setp()非常结构清晰的处理 (work transparently with)对象列表或者单一对象。你可以使用Python的关键字参数或者MATLAB风格的 字符串/值 对(string/value pairs)

lines = plt.plot(x1,y1,x2,y2)
plt.setp(lines,color='r',linewidth=2.0)#keyword args
plt.setp(lines,'color','r','linewidth',2.0)#MATLAB风格的命令

下面是一些Line2D可以使用的属性:

alpha: float (0.0 transparent through 1.0 opaque)
animated: [True | False]
antialiased or aa: [True | False]
clip_box: a :class:matplotlib.transforms.Bbox instance
clip_on: [True | False]
clip_path: [ (:class:~matplotlib.path.Path, :class:~matplotlib.transforms.Transform) | :class:~matplotlib.patches.Patch | None ]
color or c: any matplotlib color
contains: a callable function
dash_capstyle: [‘butt’ | ‘round’ | ‘projecting’]
dash_joinstyle: [‘miter’ | ‘round’ | ‘bevel’]
dashes: sequence of on/off ink in points
drawstyle: [‘default’ | ‘steps’ | ‘steps-pre’ | ‘steps-mid’ | ‘steps-post’]
figure: a :class:matplotlib.figure.Figure instance
fillstyle: [‘full’ | ‘left’ | ‘right’ | ‘bottom’ | ‘top’ | ‘none’]
gid: an id string
label: string or anything printable with ‘%s’ conversion.
linestyle or ls: [‘solid’ | ‘dashed’, ‘dashdot’, ‘dotted’ | (offset, on-off-dash-seq) | '-' | '--' | '-.' | ':' | 'None' | ' ' | '']
linewidth or lw: float value in points
marker: :mod:A valid marker style <matplotlib.markers>
markeredgecolor or mec: any matplotlib color
markeredgewidth or mew: float value in points
markerfacecolor or mfc: any matplotlib color
markerfacecoloralt or mfcalt: any matplotlib color
markersize or ms: float
markevery: [None | int | length-2 tuple of int | slice | list/array of int | float | length-2 tuple of float]
path_effects: unknown
picker: float distance in points or callable pick function fn(artist, event)
pickradius: float distance in points
rasterized: [True | False | None]
sketch_params: unknown
snap: unknown
solid_capstyle: [‘butt’ | ‘round’ | ‘projecting’]
solid_joinstyle: [‘miter’ | ‘round’ | ‘bevel’]
transform: a :class:matplotlib.transforms.Transform instance
url: a url string
visible: [True | False]
xdata: 1D array
ydata: 1D array
zorder: any number


为了得到线可以设置属性的列表,可以把line或线的列表作为参数传递给setp()函数,例如:

In [69]: lines=plt.plot([1,2,3])
In [70]: plt.setp(lines)
alpha:float
animated:[True|False]
…….
snip

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值