文章詳情頁
Python使用matplotlib繪制圓形代碼實例
瀏覽:3日期:2022-07-24 13:05:32
1、定義一個畫圓的函數
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、調用 plot_circle()
plot_circle((5, 5), r=3)
調整坐標軸,重新繪圖
import matplotlib.pyplot as pltplt.xlim(0, 15)plt.ylim(0, 15)plot_circle((5, 5),r=3)
只要將步驟 1 函數定義的復雜一些,還可以實現很多玩法。
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。
相關文章:
排行榜