脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - Python - Python实现的圆形绘制(画圆)示例

Python实现的圆形绘制(画圆)示例

2021-01-10 00:42罗兵 Python

这篇文章主要介绍了Python实现的圆形绘制(画圆),结合实例形式分析了Python基于numpy与matplotlib模块的数学运算及图形绘制相关操作技巧,需要的朋友可以参考下

本文实例讲述了Python实现的圆形绘制。分享给大家供大家参考,具体如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# -*- 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.zyiz.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.zyiz.net')
# ==========================================
plt.show()

运行效果:

Python实现的圆形绘制(画圆)示例.

Python实现的圆形绘制(画圆)示例

希望本文所述对大家Python程序设计有所帮助。

原文链接:http://www.cnblogs.com/hhh5460/p/6361123.html

延伸 · 阅读

精彩推荐