Python实现的圆形绘制的方法
更新:HHH   时间:2023-1-7


这篇文章给大家分享的是有关Python实现的圆形绘制的方法的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

具体实现代码如下:

# -*- coding:utf-8 -*-
#! python3
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')
plt.title('www.jb51.net')
# ==========================================
# 方法二:标准方程
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.title('www.jb51.net')
# ==========================================
plt.show()

运行效果:

.

感谢各位的阅读!关于“Python实现的圆形绘制的方法”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

返回开发技术教程...