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

Turtle庫(kù)是python語(yǔ)言中一個(gè)很流行的繪制圖像的函數(shù)庫(kù),想象一個(gè)小烏龜,在一個(gè)橫軸為x、縱軸為y的坐標(biāo)系原點(diǎn),(0,0)位置開始,它根據(jù)一組函數(shù)指令的控制,在這個(gè)平面坐標(biāo)系中移動(dòng),從而在它爬行的路徑上繪制了圖形。
Turtle庫(kù)用于繪制線、圓、其他形狀或者文本。
顯示小烏龜?shù)呐佬熊壽E,初始小烏龜在(0, 0),前進(jìn)方向?yàn)?x 軸正方向。
turtle.circle(radius,extent,step)
·radius 是必需的,表示半徑,正值時(shí)逆時(shí)針旋轉(zhuǎn);
·extent 表示度數(shù),用于繪制圓?。?/p>
·step 表示邊數(shù),可用于繪制正多邊形;
·extent 和 step 參數(shù)可有可無(wú)。
繪制圓形
import turtle
turtle.color('red')
turtle.circle(80)
turtle.done()運(yùn)行結(jié)果:
相關(guān)推薦:《Python教程》
二、使用Numpy庫(kù)
# -*- 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()運(yùn)行效果:
方法一:
方法二:
文章題目:創(chuàng)新互聯(lián)Python教程:python怎么畫圓
當(dāng)前URL:http://www.5511xx.com/article/dheoppp.html


咨詢
建站咨詢
