matplotlib.pyplot.plot()是matplotlib庫中的一個函數,plot有繪圖之意,py是python的簡寫。
matplotlib.pyplot.plot(*args, **kwargs)
下面是plot函數得兩種形式,plot把x與y畫成線,或者標記(Plot y versus x as lines and/or markers),第二種形式在一個圖中要畫出多條線的話可以用,同樣也可以重複使用形式一達到目的plot([x], y, [fmt], data=None, **kwargs)
plot([x], y, [fmt], [x2], y2, [fmt2], ..., **kwargs)其中可以缺少x的數據,會自動以自然數的形式補齊(0,1......n)
1.輸入數據類型
(1)x 和 y 都是一維列表或數組;
(2)x 是n*1數組或列表,y是一維長度爲n的數組或列表;
(3)x是m*n數組或列表,y是m*1列表或數組。如下例子,畫出的圖如下。
會產生20個點,十對。
x = [[-0.07816532 0.05068012 0.07786339 0.05285819 0.07823631 0.0644473
0.02655027 -0.00259226 0.04067226 -0.00936191]
[ 0.0090156 0.05068012 -0.03961813 0.0287581 0.03833367 0.0735286
-0.07285395 0.1081111 0.01556684 -0.04664087]]
y = [ 201.12401963 150.05917612]
matplotlib.pyplot.plot(x,y)
2.fmt是shortcut string notation ,其形式爲
fmt = '[color][marker][line]',顏色,點標記類型,畫線類型。
(1)顏色表:
character | color |
---|---|
'b' | blue |
'g' | green |
'r' | red |
'c' | cyan |
'm' | magenta |
'y' | yellow |
'k' | black |
'w' | white |
(2)點類型
character | description |
---|---|
'.' | 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 |
(3)線條類型
character | description |
---|---|
'-' | solid line style |
'--' | dashed line style |
'-.' | dash-dot line style |
':' | dotted line style |
3.**kwargs包含fmt,如果即在fmt中定義了,然後又重複在**kwargs中定義,那麼以**kwargs爲準。
Property | Description |
---|---|
agg_filter | a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array |
alpha | float (0.0 transparent through 1.0 opaque) |
animated | bool |
antialiased or aa | bool |
clip_box | a Bbox instance |
clip_on | bool |
clip_path | [(Path , Transform ) | 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 Figure instance |
fillstyle | [‘full’ | ‘left’ | ‘right’ | ‘bottom’ | ‘top’ | ‘none’] |
gid | an id string |
label | object |
linestyle or ls | [‘solid’ | ‘dashed’, ‘dashdot’, ‘dotted’ | (offset, on-off-dash-seq) | '-' | '--' | '-.' | ':' | 'None' | ' ' | '' ] |
linewidth or lw | float value in points |
marker | A valid marker style |
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 | AbstractPathEffect |
picker | float distance in points or callable pick function fn(artist,event) |
pickradius | float distance in points |
rasterized | bool or None |
sketch_params | (scale: float, length: float, randomness: float) |
snap | bool or None |
solid_capstyle | [‘butt’ | ‘round’ | ‘projecting’] |
solid_joinstyle | [‘miter’ | ‘round’ | ‘bevel’] |
transform | a matplotlib.transforms.Transform instance |
url | a url string |
visible | bool |
xdata | 1D array |
ydata | 1D array |
zorder | float |