溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Python matplotlib Line2D對(duì)象怎么用

發(fā)布時(shí)間:2021-11-30 09:51:56 來源:億速云 閱讀:325 作者:小新 欄目:云計(jì)算

這篇文章主要介紹 Python matplotlib Line2D對(duì)象怎么用,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!

總括

matplotlib.pyplot很像MATLAB。它的每一個(gè)函數(shù)都會(huì)對(duì)現(xiàn)有的圖形進(jìn)行更改:比如建立一個(gè)圖形(figure),創(chuàng)建畫圖區(qū)域,在畫圖區(qū)域做出線條,使用標(biāo)簽裝飾。
如果你傳入了一個(gè)簡(jiǎn)單的list或者array,matplotlib會(huì)把它當(dāng)成y值,并自動(dòng)生成x值。事實(shí)上所有序列都會(huì)被轉(zhuǎn)換為numpy arrays。

import matplotlib.pyplot as plt
plt.plot([1,2,3,4])
plt.ylabel('some numbers')
plt.show()

Python matplotlib Line2D對(duì)象怎么用

當(dāng)你傳入兩個(gè)list或者array時(shí),第一個(gè)會(huì)被當(dāng)成x值,第二個(gè)會(huì)被當(dāng)成y值,而且你可以通過第三個(gè)參數(shù)設(shè)置顯示的形狀和顏色(這是一個(gè)組合),當(dāng)然你也可以分別設(shè)置形狀和顏色。通過plt.axis(xmin, xmax, ymin, ymax)函數(shù)你可以設(shè)置x軸,y軸的最大值和最小值:

import matplotlib.pyplot as plt
plt.plot([1,2,3,4], [1,4,9,16], 'ro')
plt.axis([0, 6, 0, 20])
plt.show()

Python matplotlib Line2D對(duì)象怎么用

Line2D對(duì)象

Line2D

Bases: matplotlib.artist.Artistclass 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)

屬性控制

有三種方式設(shè)置線的屬性
1)直接在plot()函數(shù)中設(shè)置

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

2)通過獲得線對(duì)象,對(duì)線對(duì)象進(jìn)行設(shè)置

line, = plt.plot(x, y, '-')line.set_antialiased(False) # turn off antialising

3)獲得線屬性,使用setp()函數(shù)設(shè)置

lines = plt.plot(x1, y1, x2, y2)# use keyword argsplt.setp(lines, color='r', linewidth=2.0)
PropertyValue Type
alphafloat
animated[True False]
antialiased or aa[True False]
clip_boxa matplotlib.transform.Bbox instance
clip_on[True False]
clip_patha Path instance and a Transform instance, a Patch
color or cany matplotlib color
containsthe hit testing function
dash_capstyle[‘butt’ ‘round’ ‘projecting’]
dash_joinstyle[‘miter’ ‘round’ ‘bevel’]
dashessequence of on/off ink in points
data(np.array xdata, np.array ydata)
figurea matplotlib.figure.Figure instance
labelany string
linestyle or ls[‘-’ ‘–’ ‘-.’ ‘:’ ‘steps’ …]
linewidth or lwfloat value in points
lod[True False]
marker[‘+’ ‘,’ ‘.’ ‘1’ ‘2’ ‘3’ ‘4’]
markeredgecolor or mecany matplotlib color
markeredgewidth or mewfloat value in points
markerfacecolor or mfcany matplotlib color
markersize or msfloat
markevery[ None integer (startind, stride) ]
pickerused in interactive line selection
pickradiusthe line pick selection radius
solid_capstyle[‘butt’ ‘round’ ‘projecting’]
solid_joinstyle[‘miter’ ‘round’ ‘bevel’]
transforma matplotlib.transforms.Transform instance
visible[True False]
xdatanp.array
ydatanp.array
zorderany number
linestyledescription
‘-‘?or?’solid’solid line
‘–’?or?’dashed’dashed line
‘-.’?or?’dashdot’dash-dotted line
‘:’?or?’dotted’dotted line
‘None’draw nothing
‘?’draw nothing
draw nothing
markerdescription
“.”point
“,”pixel
“o”circle
“v”triangle_down
“^”triangle_up
“<”triangle_left
“>”triangle_right
“1”tri_down
“2”tri_up
“3”tri_left
“4”tri_right
“8”octagon
“s”square
“p”pentagon
“P”plus (filled)
“*”star
“h”hexagon1
“H”hexagon2
“+”plus
“x”x
“X”x (filled)
“D”diamond
“d”thin_diamond
“_”hline
TICKLEFTtickleft
TICKRIGHTtickright
TICKUPtickup
TICKDOWNtickdown
CARETLEFTcaretleft (centered at tip)
CARETRIGHTcaretright (centered at tip)
CARETUPcaretup (centered at tip)
CARETDOWNcaretdown (centered at tip)
CARETLEFTBASEcaretleft (centered at base)
CARETRIGHTBASEcaretright (centered at base)
CARETUPBASEcaretup (centered at base)
“None”,?”?”?or?”“nothing
‘ ... ’render the string using mathtext.
vertsa list of (x, y) pairs used for Path vertices. The center of the marker is located at (0,0) and the size is normalized.
patha?Path?instance.

以上是“ Python matplotlib Line2D對(duì)象怎么用”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI