python circle函数如何画圆_Python Matplotlib画圆

同时需要了解Numpy和Matplotlib相关知识。

看代码吧,仔细了解清楚每句代码,每个函数。

# -*- 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.ai8py.com')

# ==========================================

# 方法二:标准方程

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) #绘图网格

#plot()二维线画图函数,若y和x为同维向量,则以x为横坐标,y为纵坐标绘制连线图。

axes.plot(x, y) # 上半部

axes.plot(x, -y) # 下半部

plt.axis('equal')#轴对称

plt.title('www.ai8py.com')#窗口标题

# ==========================================

plt.show()

a1002.png

20190614增加,用turtle更容易。

# !/usr/bin/env python3

# -*- coding: utf-8 -*-

import turtle

def main():

turtle.title('www.ai8py.com')

turtle.circle(100)

turtle.mainloop()

if __name__ == '__main__':

main()

turtle.png

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值