Python matplotlib 线图(plt.plot())

http://matplotlib.org/api/lines_api.html#matplotlib.lines.Line2D

线图

生成线图对象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)

plt.plot()参数设置

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])

没有更多推荐了,返回首页