本文实例讲述了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()

运行效果:

89f1c76d1f99a9a55e92ff8fd278fd49.png.

ccb6974e8b2f67a371ce316fef7af184.png

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

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

Logo

GitCode 天启AI是一款由 GitCode 团队打造的智能助手,基于先进的LLM(大语言模型)与多智能体 Agent 技术构建,致力于为用户提供高效、智能、多模态的创作与开发支持。它不仅支持自然语言对话,还具备处理文件、生成 PPT、撰写分析报告、开发 Web 应用等多项能力,真正做到“一句话,让 Al帮你完成复杂任务”。

更多推荐