1. 程式人生 > >Python matplotlib 線圖(plt.plot())

Python matplotlib 線圖(plt.plot())

線圖

生成線圖物件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
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]
資料點的設定[‘+’ ‘,’ ‘.’ ‘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)

其他

一個應用,在圖上做一條垂直於x軸的線段,要用兩個相同x,不同y的點來刻畫
plt.plot([x,x],[0,y])