Python使用matplotlib繪制圓形代碼實(shí)例
1、定義一個(gè)畫圓的函數(shù)
import numpy as npimport matplotlib.pyplot as plt def plot_circle(center=(3, 3),r=2): x = np.linspace(center[0] - r, center[0] + r, 5000) y1 = np.sqrt(r**2 - (x-center[0])**2) + center[1] y2 = -np.sqrt(r**2 - (x-center[0])**2) + center[1] plt.plot(x, y1, c=’k’) plt.plot(x, y2, c=’k’) plt.show()
2、調(diào)用 plot_circle()
plot_circle((5, 5), r=3)
調(diào)整坐標(biāo)軸,重新繪圖
import matplotlib.pyplot as pltplt.xlim(0, 15)plt.ylim(0, 15)plot_circle((5, 5),r=3)
只要將步驟 1 函數(shù)定義的復(fù)雜一些,還可以實(shí)現(xiàn)很多玩法。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. Python TestSuite生成測(cè)試報(bào)告過程解析2. 增大python字體的方法步驟3. Spring security 自定義過濾器實(shí)現(xiàn)Json參數(shù)傳遞并兼容表單參數(shù)(實(shí)例代碼)4. 在JSP中使用formatNumber控制要顯示的小數(shù)位數(shù)方法5. Vue作用域插槽實(shí)現(xiàn)方法及作用詳解6. IntelliJ IDEA設(shè)置默認(rèn)瀏覽器的方法7. JAMon(Java Application Monitor)備忘記8. Python os庫(kù)常用操作代碼匯總9. Python 如何展開嵌套的序列10. 如何清空python的變量
