新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:python怎么畫圓
一、使用Turtle庫

Turtle庫是python語言中一個很流行的繪制圖像的函數(shù)庫,想象一個小烏龜,在一個橫軸為x、縱軸為y的坐標(biāo)系原點,(0,0)位置開始,它根據(jù)一組函數(shù)指令的控制,在這個平面坐標(biāo)系中移動,從而在它爬行的路徑上繪制了圖形。
Turtle庫用于繪制線、圓、其他形狀或者文本。
顯示小烏龜?shù)呐佬熊壽E,初始小烏龜在(0, 0),前進(jìn)方向為 x 軸正方向。
turtle.circle(radius,extent,step)
·radius 是必需的,表示半徑,正值時逆時針旋轉(zhuǎn);
·extent 表示度數(shù),用于繪制圓??;
·step 表示邊數(shù),可用于繪制正多邊形;
·extent 和 step 參數(shù)可有可無。
繪制圓形
import turtle
turtle.color('red')
turtle.circle(80)
turtle.done()運行結(jié)果:
相關(guān)推薦:《Python教程》
二、使用Numpy庫
# -*- coding:utf-8 -*-
#! python3
import numpy as np
import matplotlib.pyplot as plt
# ==========================================
# 圓的基本信息
# 1.圓半徑
r = 2.0
# 2.圓心坐標(biāo)
a, b = (0., 0.)
# ==========================================
# 方法一:參數(shù)方程
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')
# ==========================================
# 方法二:標(biāo)準(zhǔn)方程
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()運行效果:
方法一:
方法二:
網(wǎng)頁名稱:創(chuàng)新互聯(lián)Python教程:python怎么畫圓
鏈接分享:http://fisionsoft.com.cn/article/dheoppp.html


咨詢
建站咨詢
