python 畫圓


import numpy as np
import matplotlib.pyplot as plt

# ==========================================
# 圓的基本信息
# 1.圓半徑
r = 2.0
# 2.圓心坐標
a, b = (0., 0.)

# ==========================================
# 方法一:參數方程
theta = np.arange(0, 2*np.pi, 0.01)
x = a + r * np.cos(theta)
y = b + r * np.sin(theta)


fig = plt.figure() 
axes = fig.add_subplot(111) 
axes.plot(x, y)

axes.axis('equal')

# ==========================================
# 方法二:標准方程
x = np.arange(a-r, a+r, 0.01)
y = b + np.sqrt(r**2 - (x - a)**2)


fig = plt.figure() 
axes = fig.add_subplot(111) 
axes.plot(x, y) # 上半部
axes.plot(x, -y) # 下半部

plt.axis('equal')

# ==========================================
plt.show()


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM