標籤:多個 red show iter tar util mon dash row
matplotlib是python中很強大的繪圖工具,在機器學習中經常用到
首先是匯入
import matplotlib.pyplot as plt
plt中有很多方法,記錄下常用的方法
plt.plot()該方法用來畫圖,第一個參數是y值,第二個參數是x值,第三個參數是由兩個值構成的字串,第一個值是顏色,第二個值是線的類型
顏色的可選值有
| ‘b’ |
blue |
| ‘g’ |
green |
| ‘r’ |
red |
| ‘c’ |
cyan |
| ‘m’ |
magenta |
| ‘y’ |
yellow |
| ‘k’ |
black |
| ‘w’ |
white |
線的類型有
‘-‘ |
solid line style |
‘--‘ |
dashed line style |
‘-.‘ |
dash-dot line style |
‘:‘ |
dotted line style |
‘.‘ |
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 |
如‘r.’即紅色的點
可以一次性畫出多個點
plt.plot([1,2,3,4])會畫出一條經過(0,1),(1,2),(2,3),(3,4)的直線
如果沒有指定x值,預設從0,開始,步長為1
plt.axis([xmin, xmax, ymin, ymax])指定x軸和y軸的起始點和結束點
plt.xlabel(‘x‘)
plt.ylabel(‘y‘)
為x,y軸分別指定一個名字
plt.figure()畫多張圖,傳入一個遞增的數字
plt.subplot(numrows, numcols, fignum)將圖分成numrows行,numcols列
plt.clf()清除之前畫的點
plt.cla()清除當前軸
plt.text(x1,x2,text)在某個點上添加文字
plt.title(title)給圖取個標題
plt.show()將圖顯示出來
官方文檔http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.plot
python matplotlib.pyplot學習記錄