Python使用matplotlib實現繪製自訂圖形功能樣本,pythonmatplotlib

來源:互聯網
上載者:User

Python使用matplotlib實現繪製自訂圖形功能樣本,pythonmatplotlib

本文執行個體講述了Python使用matplotlib實現繪製自訂圖形功能。分享給大家供大家參考,具體如下:

一 代碼

from matplotlib.path importPathfrom matplotlib.patches importPathPatchimport matplotlib.pyplot as pltfig, ax = plt.subplots()#定義繪圖指令與控制點座標#其中MOVETO表示將繪製起點移動到指定座標#CURVE4表示使用4個控制點繪製3次貝茲路徑#CURVE3表示使用3個控制點繪製2次貝茲路徑#LINETO表示從當前位置繪製直線到指定位置#CLOSEPOLY表示從當前位置繪製直線到指定位置,並閉合多邊形path_data =[(Path.MOVETO,(1.58,-2.57)),(Path.CURVE4,(0.35,-1.1)),(Path.CURVE4,(-1.75,2.0)),(Path.CURVE4,(0.375,2.0)),(Path.LINETO,(0.85,1.15)),(Path.CURVE4,(2.2,3.2)),(Path.CURVE4,(3,0.05)),(Path.CURVE4,(2.0,-0.5)),(Path.CURVE3,(3.5,-1.8)),(Path.CURVE3,(2,-2)),(Path.CLOSEPOLY,(1.58,-2.57)),]codes, verts = zip(*path_data)path =Path(verts, codes)#按指令和座標進行繪圖patch =PathPatch(path, facecolor='r', alpha=0.9)ax.add_patch(patch)# 繪製控制多邊形和連接點x, y = zip(*path.vertices)line,= ax.plot(x, y,'go-')#顯示網格ax.grid()#設定座標軸刻度大小一致,可以更真實地顯示圖形ax.axis('equal')plt.show()

二 運行結果

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.